﻿#include "mainwidget.h"
#include "ui_mainwidget.h"

#define INTERFACE_SHORTCUT 1    //快捷功能界面
#define INTERFACE_ACCESS 2    //辅助功能界面

#ifdef Q_OS_WIN
#include <Windows.h>
#endif
MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget),
    m_pPatternSelectWi(NULL),
    m_pParameterSetDlg(NULL),
    m_pPatternManageWi(NULL),
    m_pSensorInputWi(NULL),
    m_pControlActionWi(NULL),
    m_pMainWidgetFunction(NULL),
    m_initflag(0),
    m_timoutflag(0),
    m_pTimer(NULL),
    m_pConTimer(NULL),
    m_conFlag(0),
    m_linkSta(0)
{
    ui->setupUi(this);

    setWindowFlags (Qt::Widget |
                    Qt::Window |
                    Qt::FramelessWindowHint  |  // 无边框窗口
                    //    Qt::WindowStaysOnTopHint |  // 顶层窗口
                    Qt::Widget);

    setFocusPolicy(Qt::NoFocus);

    mousePressX = 0;
    mousePressY = 0;
    mouseReleaseX = 0;
    mouseReleaseY = 0;

    this->move(0+g_mainWidgetPos.x(),0+g_mainWidgetPos.y());
    initialize();

    showWorkSpeed(QString("2400"));//初始化数码管的速度是0
    ui->labelSpeed->hide();
}

MainWidget::~MainWidget()
{
    if(m_pTimer != NULL)
    {
        delete m_pTimer;
    }

    if(m_pConTimer != NULL)
    {
        delete m_pConTimer;
    }

    if(m_pMinTimer != NULL)
    {
        delete m_pMinTimer;
    }

    if(m_pWifiConTimer != NULL)
    {
        delete m_pWifiConTimer;
    }

    if(m_pRefreshVer != NULL)
    {
        delete m_pRefreshVer;
    }
    
    if(m_pPatternSelectWi != NULL)
    {
        delete m_pPatternSelectWi;
    }

    if(m_pParameterSetDlg != NULL)
    {
        delete m_pParameterSetDlg;
    }

    if(m_pSensorInputWi != NULL)
    {
        delete m_pSensorInputWi;
    }

    if(m_pControlActionWi != NULL)
    {
        delete m_pControlActionWi;
    }

    if(m_pMainWidgetFunction != NULL)
    {
        delete m_pMainWidgetFunction;
    }
    if(m_pScanComThread != NULL)
    {
        //        m_pScanComThread->wait();
        m_pScanComThread->quit();
        m_pScanComThread->deleteLater();
    }
    if(m_pScanComPort != NULL)
        m_pScanComPort->deleteLater();

    delete ui;
}

void MainWidget::initialize()
{
    memset(&m_expara, 0, sizeof(FileExecPara));
    m_setControlStyle.setUiName(this->objectName());

    hideMenuFrame();
    //主界面按钮选中
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);

    ui->frameForwardBack->setVisible(false);
    clearFileInfo();//清除文件信息

    ui->labelWorkState->setVisible(true); //正常工作/模拟工作
    ui->labelEnableWorkState->setVisible(false);//允许工作/禁止工作

    memset(&m_mcStatus,0,sizeof(MCStatus));

    //定时器
    m_pTimer = new QTimer(this);
    m_pTimer->setInterval(1000);    // 设置定时间隔1秒
    connect(m_pTimer, SIGNAL(timeout()), this, SLOT(onOneSecondTimer()));

    //定时器
    m_pConTimer = new QTimer(this);
    m_pConTimer->setInterval(5000);    // 设置定时间隔5秒
    connect(m_pConTimer, SIGNAL(timeout()), this, SLOT(onFiveSecondTimer()));

    //定时器
    m_pWifiConTimer = new QTimer(this);
    m_pWifiConTimer->setInterval(100000);    // 设置定时间隔10分钟
    connect(m_pWifiConTimer, SIGNAL(timeout()), this, SLOT(onTenMiniteTimer()));

    //测试花样刷新的定时器
    m_pRefreshPatternTimer = new QTimer(this);
    m_pRefreshPatternTimer->setInterval(300);    // 设置时间
    connect(m_pRefreshPatternTimer, SIGNAL(timeout()), this, SLOT(onRefreshPatternTimer()));

    //一分钟定时任务,记录当前系统时间,用于上电时计算关机时间
    m_pMinTimer = new QTimer(this);
    m_pMinTimer->setInterval(60000);    // 设置定时间隔60秒
    connect(m_pMinTimer, SIGNAL(timeout()), this, SLOT(onOneMinTimer()));

    m_pRefreshVer = new QTimer(this);
    m_pRefreshVer->setInterval(1000);
    connect(m_pRefreshVer, SIGNAL(timeout()), this, SLOT(onRefreshVer()));
    m_pRefreshVer->start();

    m_curFilePath.clear();
    m_imageZoom = 0;//花样图片缩放值
    m_imageMoveX = 0;//花样图片平移值X
    m_imageMoveY = 0;//花样图片平移值Y
    m_curDatIdx = 0;//当前针数索引
    m_curPages = 1; // 当前页
    m_itemPerPage = 24;//快捷功能和辅助功能界面各24个按钮
    m_curRpm = -1;
    m_workStatus = 0;
    m_forwardBackNeedleIdx = 0;//前进回退时的针数索引
    m_ifHMIDecrypt = 1;
    m_connectMode = USE_TCP_COMM;

    m_speedLevel = 2;//速度默认等于2
    m_errorCode = 0;//错误代码
    m_backPosFlag = 0;
}

//初始化窗体
void MainWidget::initAllWindows(s16 ifHMIDecrypt,s16 connectMode)
{
    m_connectMode = connectMode;
    m_ifHMIDecrypt = ifHMIDecrypt;
    if (m_initflag <= 1)
    {
        connect(g_pCurEmbData,SIGNAL(siDrawNeedleIdx(int)),this,SLOT(slotChangeProgressBar(int)));
        m_initflag = 2;
        sendInitString(QString(tr("Init windows...")));//初始化窗体...
        initControl();//初始化界面控件
        initQuickFunBtn();//初始化快捷功能中的快捷按钮
        initAssisitBtn();//初始化辅助功能中的辅助功能按钮
        initPatternSetBtn();//初始化花样设置功能中的功能按钮
        initParaSetBtn();//初始化参数设置功能中的功能按钮

        m_pMainWidgetFunction = new MainWidgetFunction();//主界面功能函数对象
        m_pMainWidgetFunction->setErrorCodeAndStateList(m_errorCodeAndStateItemList);
        connect(m_pMainWidgetFunction, SIGNAL(siSetButtonUserLogo(int)), this, SLOT(slotSetButtonRootLogo(int)));
        connect(m_pMainWidgetFunction, SIGNAL(siClearPatternBreakLineNum()),this,SLOT(slotClearPatternBreakLineNum()));
        connect(m_pMainWidgetFunction, SIGNAL(siDebugState()),this,SLOT(slotDebugState())); //调试模式改变字体颜色
        connect(m_pMainWidgetFunction, SIGNAL(siClearPattern()), this, SLOT(slotIfFileExist()));//花样总清后，清除当前所选花版路径//两个信号用一个槽
        connect(m_pMainWidgetFunction, SIGNAL(siClearPatternFcg()), this, SLOT(slotClearPatternFcg()));//花样fcg总清后，清除当前所选花版路径
        connect(m_pMainWidgetFunction,SIGNAL(siShowPercentage(int)),this,SLOT(slotShowPercentage(int)));
        connect(m_pMainWidgetFunction,SIGNAL(siWifiState(bool)),this,SLOT(slotRefreshWifiIcon(bool)));

        //connect(m_pMainWidgetFunction, SIGNAL(siRecieveLotDat()),this,SLOT(slotLotDat()));//测试物联网用

        m_pPatternSelectWi = new PatternSelectWidget(this);
        m_pPatternSelectWi->hide();
        connect(m_pPatternSelectWi, SIGNAL(siSelectPattern(QString,s16)), this, SLOT(slotShowPatternPara(QString,s16)));

        m_pPatternManageWi = new PatternManageWidget(this);
        connect(m_pPatternManageWi, SIGNAL(siDeletePattern()), this, SLOT(slotIfFileExist()));
        connect(m_pPatternManageWi, SIGNAL(siReplacePattrn(QString)), this, SLOT(slotReplacePattrn(QString)));

        m_pParameterSetDlg->hide();
        connect(m_pParameterSetDlg,SIGNAL(siUserLogin(s16)),m_pMainWidgetFunction,SLOT(slotUserLogin(s16)));
        connect(g_pMachine, SIGNAL(siParaChange(int, int)),
                m_pParameterSetDlg, SLOT(paraChange(int, int)));// 参数改变

        connect(m_pParameterSetDlg,SIGNAL(siHMIDecrypt(QString)),m_pMainWidgetFunction,SLOT(slotHMIDecrypt(QString)));
        connect(m_pParameterSetDlg,SIGNAL(siExit()),m_pMainWidgetFunction,SLOT(slotExitApp()));//超级用户退出程序
        connect(m_pParameterSetDlg,SIGNAL(siChangePassword()),m_pMainWidgetFunction,SLOT(slotChangePassword()));//超级用户修改一级密码
        connect(m_pParameterSetDlg,SIGNAL(siDeleteIni()),m_pMainWidgetFunction,SLOT(slotDeleteIni()));//删除执行目录下的config.ini文件
        connect(m_pParameterSetDlg,SIGNAL(siImportCSV()),m_pMainWidgetFunction,SLOT(slotImportCSV()));
        connect(m_pParameterSetDlg,SIGNAL(siDeleteCSV()),m_pMainWidgetFunction,SLOT(slotDeleteCSV()));
        connect(m_pParameterSetDlg,SIGNAL(siResetCSV()),m_pMainWidgetFunction,SLOT(slotResetCSV()));
        connect(m_pParameterSetDlg,SIGNAL(siPatternClear()),m_pMainWidgetFunction,SLOT(slotPatternClear()));//超级用户花样总清
        connect(m_pParameterSetDlg,SIGNAL(siDebugMode()),m_pMainWidgetFunction,SLOT(slotDebugMode()));//超级用户界面调试模式

        connect(m_pMainWidgetFunction,SIGNAL(siAfterDeleteFileid()),this,SLOT(slotClearPatternFcg()));//超级用户删除花样fcg影响fileid的数据之后

        m_pPatternManageWi->hide();

        m_pSensorInputWi->hide();
        m_pControlActionWi->hide();
        connect(this, SIGNAL(siSpeed(int)),m_pControlActionWi,SLOT(slotSpeed(int))); //手动换挡

        QTimer timer;
        connect(&timer, SIGNAL(timeout()), this, SLOT(slotWaitTimout()));
        timer.start(1000);

        m_timoutflag = 0;
        do
        {
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }while(m_timoutflag == 0);
        timer.stop();

        sendInitString(QString(tr("Init communication...")));//初始化通讯...

        connect(g_pMachine, SIGNAL(siSensorEnBitmap(SensorsBitmap)),
                m_pSensorInputWi, SLOT(slotRefSensorBitmap(SensorsBitmap)));//传感信号有效位图更新信号
        connect(g_pMachine, SIGNAL(siSensorChange(SensorsBitmap)),
                m_pSensorInputWi , SLOT(slotRefSensorsDat(SensorsBitmap)));//传感信号更新

        //显示报错信息
        connect(g_pMachine, SIGNAL(siStatusChange(int)), this, SLOT(slotMachineStatus(int)));

        // 等待通讯结束....
        timer.start(1000);
        m_timoutflag = 0;
        do
        {
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }while(m_timoutflag == 0);
        timer.stop();

        refConnectUi(-1);//刷新连接

        m_pTimer->start();//1秒检查一次连接状态
        m_pConTimer->start();//5秒检查一次连接是否断开，若不需要检测与下位机的心跳包时注释掉此行代码
        //m_pMinTimer->start();//1分钟记录一次当前系统时间
        //m_pMainWidgetFunction->setShutDownTime();//开启计算关机时间

        //窗体初始化完成后自动加载文件并显示、发送
        m_curFilePath = g_pSettings->readFromIniFile("Pattern/name").toString();
        slotShowPatternPara(m_curFilePath,-1);//不显示花样设置窗体，直接加载花样参数

        //扫码器
        if(g_emMacType == MACHINE_FIVEHEADPRECISIONSEWING)
        {
            m_pScanComThread = new QThread(this);
            m_pScanComPort = new ComPort();
            m_pScanComPort->setComPortName("/dev/ttyS2");

            m_pScanComPort->moveToThread(m_pScanComThread);
            connect(m_pScanComThread, SIGNAL(started()), m_pScanComPort, SLOT(initComm()));
            connect(m_pScanComThread, SIGNAL(finished()), m_pScanComPort, SLOT(deleteLater()));  // 退出删除对象
            connect(m_pScanComPort, SIGNAL(siReceiveData(QByteArray)), this, SLOT(slotReceScanData(QByteArray)));

            m_pScanComThread->start();
        }

        //平板切割机
        if(g_emMacType == MACHINE_FLATCUTTINGMAC || g_emMacType == MACHINE_FLYFLATCUTTING)
        {
            //文件服务器
            m_pTcpServer = QSharedPointer<MyTcpServer>(new MyTcpServer(this)); //挂在父对象树中
            m_pTcpServerThread = QSharedPointer<QThread>(new QThread(this)); //挂在父对象树中
            m_pTcpServer.data()->moveToThread(m_pTcpServerThread.data());
            connect(m_pTcpServerThread.data(), SIGNAL(finished()), m_pTcpServer.data(), SLOT(deleteLater()));  // 退出删除对象
            //文件传输完成
            connect(m_pTcpServer.data(),SIGNAL(recvFileSuccess(QString)), this, SLOT(slotTcpRecvFile(QString)));

            // 监听特定的端口 如果后续想改端口可以写到配置文件
            if (!m_pTcpServer.data()->listen(QHostAddress::Any, 8081)) {
                qDebug() << "FileTrans Server could not start!";
            } else {
                qDebug() << "FileTrans Server started!";
            }

            //刀压采集 显示

            m_pKnifeGapParaDlg = QSharedPointer<KnifeGapParaDialog>(new KnifeGapParaDialog);
            m_pKnifeGapParaDlg.data()->setMainTitle(tr("Display collected data"));//显示采集数据
            m_pKnifeGapParaDlg.data()->setSubTitle("");
            m_pKnifeGapParaDlg.data()->setTypeLogo(m_setControlStyle.getTopStyleSheet("DisplayCollectedData"));
            connect(g_pMachine, SIGNAL(siParaChange(int, int)),
                    m_pKnifeGapParaDlg.data(), SLOT(recvData(int, int)));// 参数改变
        }

        s16 wifi = g_pSettings->readFromIniFile("HMI/wifi").toInt();//是否有wifi
        if(wifi == 1)
        {
            onTenMiniteTimer();
            ui->buttonWifi->setVisible(true);
            m_pWifiConTimer->start();
        }
        else
        {
            ui->buttonWifi->setVisible(false);
        }
    }
}

//不同机型不同的窗体设置
void MainWidget::initMcTypeWindows()
{
    m_pParameterSetDlg = new ParameterSetDialog(this);
    m_pControlActionWi = new ControlActionWidget(this);
    m_pSensorInputWi = new SensorInputWidget(this);

    m_quickItemList.clear();
    m_assistItemList.clear();
    m_patternSetItemList.clear();
    m_paraSetItemList.clear();

    MachineTypeFun * curMachineType = NULL;
    int waterMark = g_pSettings->readFromIniFile("HMI/waterMark").toInt();//是否带水印
    Q_UNUSED(waterMark);

    setLabelTitleText(g_emMacType);//根据机型显示主界面标题

    switch (g_emMacType) {
    case MACHINE_HIGHSPEEDSINGLEQUI:  //绗缝机
        curMachineType = new HighSingleQui();
        break;
    case MACHINE_FIVEHEADPRECISIONSEWING:  //五头精密缝
        curMachineType = new FiveHeadPrecisionSewing();
        break;

    case MACHINE_CLOTHINGMAC:  // 服装机
        curMachineType = new ClothingMac();
        break;

    case MACHINE_MULTINEEDLEROTARY: // 多针旋梭
        curMachineType = new MultiNeedleRotary();
        break;

    case MACHINE_FLATCUTTINGMAC:    //平板切割机
        curMachineType = new FlatCuttingmac();
        break;

    case MACHINE_THICK_WIRING:    //粗线布线机
        curMachineType = new ThickWiringMac();
        break;

    case MACHINE_FLYFLATCUTTING:    //飞行切割平板切割机
        curMachineType = new FlyFlatCutting();
        break;

    case MACHINE_DRAWING:    //画线机
        curMachineType = new DrawingMac();
        break;

    default:
        break;
    }

    //初始化快捷按钮列表要在初始化控件前
    m_quickItemList = curMachineType->getShortCutListByFilter();
    m_assistItemList = curMachineType->getAssistListByFilter();
    m_patternSetItemList = curMachineType->getPatternSetListByFilter();
    m_paraSetItemList = curMachineType->getParaSetListByFilter();
    m_pControlActionWi->addItemList(curMachineType->getOutCtrlListByFilter());
    //添加机器参数和工作参数
    m_pParameterSetDlg->addParaItem(curMachineType->getParasListByMcSel());
    m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK);
    m_pSensorInputWi->addSensorItems(curMachineType->getSensorList());
    m_nineBtn = curMachineType->getNinebtn();
    m_fileInfo = curMachineType->getFileInfoMSG();
    m_errorCodeAndStateItemList.clear();
    m_errorCodeAndStateItemList = curMachineType->getErrorCodeAndStateList();
    if(curMachineType != NULL)
    {
        delete curMachineType;
    }
}

void MainWidget::setLabelTitleText(MachineType type)
{
    switch (type) {

    case MACHINE_FLATCUTTINGMAC:    //平板切割机
        ui->labelTitle->setText(tr("Richpeace Slicing Control System"));//富怡切割控制系统
        break;

    case MACHINE_FLYFLATCUTTING:    //飞行切割平板切割机
        ui->labelTitle->setText(tr("Richpeace Slicing Control System"));//富怡切割控制系统
        break;

    default:
        ui->labelTitle->setText(tr("Richpeace Quilting Control System"));//富怡绗缝控制系统
        break;
    }

}

//初始化快捷功能中的快捷按钮
void MainWidget::initQuickFunBtn()
{
    for(int i = 0; i < m_quickBtnList.size(); i++)
    {
        if(i < m_quickItemList.size())
        {
            m_quickBtnList[i]->setVisible(true);
            m_quickLabelList[i]->setVisible(true);

            QString name = m_quickItemList[i].m_name;
            m_quickLabelList[i]->setText(name);

            QString topImageName = m_quickItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_quickBtnList[i]->setTopImage(btnStyle);

            int enumFun = m_quickItemList[i].m_enumFunction;
            if(enumFun == FUN_FORWARDORBACK ||//快进快退
                    enumFun == FUN_SETSTARTPOINT ||//定起始点
                    enumFun == FUN_BACKSTARTPOINT ||//回起始点
                    enumFun == FUN_NULL ||//无功能
                    enumFun == FUN_CHECKFRAME //边框检查
                    )
            {
                if(m_curFilePath.length() <= 0)//未选择文件时快进快退等按钮不可用
                {
                    m_quickBtnList[i]->setEnabled(false);
                }
            }
        }
        else
        {
            m_quickBtnList[i]->setVisible(false);
            m_quickLabelList[i]->setVisible(false);
        }
    }
}

//初始化辅助功能中的辅助按钮
void MainWidget::initAssisitBtn()
{
    for(int i = 0; i < m_assistBtnList.size(); i++)
    {
        if(i < m_assistItemList.size())
        {
            m_assistBtnList[i]->setVisible(true);
            m_assistLabelList[i]->setVisible(true);

            QString name = m_assistItemList[i].m_name;
            m_assistLabelList[i]->setText(name);

            QString topImageName = m_assistItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_assistBtnList[i]->setTopImage(btnStyle);
        }
        else
        {
            m_assistBtnList[i]->setVisible(false);
            m_assistLabelList[i]->setVisible(false);
        }
    }
}

//初始化花样设置功能中的花样设置按钮
void MainWidget::initPatternSetBtn()
{
    for(int i = 0; i < m_patternSetBtnList.size(); i++)
    {
        if(i < m_patternSetItemList.size())
        {
            m_patternSetBtnList[i]->setVisible(true);
            m_patternSetLabelList[i]->setVisible(true);

            QString name = m_patternSetItemList[i].m_name;
            m_patternSetLabelList[i]->setText(name);

            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_patternSetBtnList[i]->setTopImage(btnStyle);

            //无花样时花样参数、花样色序、参数
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
            {
                m_patternSetBtnList[i]->setEnabled(false);
            }
        }
        else
        {
            m_patternSetBtnList[i]->setVisible(false);
            m_patternSetLabelList[i]->setVisible(false);

        }
    }
}

//初始化参数设置功能中的参数设置按钮
void MainWidget::initParaSetBtn()
{
    for(int i = 0; i < m_paraSetBtnList.size(); i++)
    {
        if(i < m_paraSetItemList.size())
        {
            m_paraSetBtnList[i]->setVisible(true);
            m_paraSetLabelList[i]->setVisible(true);

            QString name = m_paraSetItemList[i].m_name;
            m_paraSetLabelList[i]->setText(name);

            QString topImageName = m_paraSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            m_paraSetBtnList[i]->setTopImage(btnStyle);
        }
        else
        {
            m_paraSetBtnList[i]->setVisible(false);
            m_paraSetLabelList[i]->setVisible(false);
        }
    }
}

void MainWidget::initPatternInfo(int beginX, int beginY,  int width, int height)
{
    ui->lab_FileName->setVisible(false);
    ui->lab_FileName_2->setVisible(false);
    ui->lab_Index->setVisible(false);
    ui->lab_Index_2->setVisible(false);
    ui->lab_StartPoint->setVisible(false);
    ui->lab_StartPoint_2->setVisible(false);
    ui->lab_Locate->setVisible(false);
    ui->lab_Locate_2->setVisible(false);
    ui->lab_Range->setVisible(false);
    ui->lab_Range_2->setVisible(false);
    ui->lab_Position->setVisible(false);
    ui->lab_Position_2->setVisible(false);
    ui->lab_Production->setVisible(false);
    ui->lab_Production_2->setVisible(false);
    ui->lab_Schedule->setVisible(false);
    ui->lab_Schedule_2->setVisible(false);

    QListIterator<PATTERNINFO> iter(m_fileInfo);
    while (iter.hasNext()) {
        PATTERNINFO item = iter.next();
        // 处理 key 和 value
        if(item == FileName){
            ui->lab_FileName->setVisible(true);
            ui->lab_FileName_2->setVisible(true);
            ui->lab_FileName->setGeometry(beginX,beginY,width,height);
            ui->lab_FileName_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == Index){
            ui->lab_Index->setVisible(true);
            ui->lab_Index_2->setVisible(true);
            ui->lab_Index->setGeometry(beginX,beginY,width,height);
            ui->lab_Index_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == BeginPoint){
            if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
                continue;

            ui->lab_StartPoint->setVisible(true);
            ui->lab_StartPoint_2->setVisible(true);
            ui->lab_StartPoint->setGeometry(beginX,beginY,width,height);
            ui->lab_StartPoint_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == Schedule){
            if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
                continue;

            ui->lab_Schedule->setVisible(true);
            ui->lab_Schedule_2->setVisible(true);
            ui->lab_Schedule->setGeometry(beginX,beginY,width,height);
            ui->lab_Schedule_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == LocalPoint){
            if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
                continue;

            ui->lab_Locate->setVisible(true);
            ui->lab_Locate_2->setVisible(true);
            ui->lab_Locate->setGeometry(beginX,beginY,width,height);
            ui->lab_Locate_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == Range){
            ui->lab_Range->setVisible(true);
            ui->lab_Range_2->setVisible(true);
            ui->lab_Range->setGeometry(beginX,beginY,width,height);
            ui->lab_Range_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == Position){
            ui->lab_Position->setVisible(true);
            ui->lab_Position_2->setVisible(true);
            ui->lab_Position->setGeometry(beginX,beginY,width,height);
            ui->lab_Position_2->setGeometry(beginX,beginY,width,height);
        }
        else if(item == Production){
            ui->lab_Production->setVisible(true);
            ui->lab_Production_2->setVisible(true);
            ui->lab_Production->setGeometry(beginX,beginY,width,height);
            ui->lab_Production_2->setGeometry(beginX,beginY,width,height);
        }
        beginY += height;
    }

}

void MainWidget::setFrameNineBtnStyle()
{
    switch (m_speedLevel)
    {
    case 1:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_1"));
        break;
    case 2:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_2"));
        break;
    case 3:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_3"));
        break;
    default:
        ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle1"));
        break;
    }
}

//清除文件信息
void MainWidget::clearFileInfo()
{
    ui->lab_FileName_2->setText("");
    ui->lab_Index_2->setText("0/0");
    ui->lab_StartPoint_2->setText("0/0");
    ui->lab_Locate_2->setText("0/0");
    ui->lab_Range_2->setText("0/0");
    ui->lab_Position_2->setText("0/0");
    ui->lab_Production_2->setText("0");
    ui->lab_Schedule_2->setText("0%");
}

//初始化窗体控件，包括位置、尺寸、样式
void MainWidget::initControl()
{
    ui->buttonShortCutPgDn->setVisible(false);
    ui->buttonShortCutPgUp->setVisible(false);
    ui->labelShortCutPage->setVisible(false);
    ui->buttonAssistPgDn->setVisible(false);
    ui->buttonAssistPgUp->setVisible(false);
    ui->labelAssistPage->setVisible(false);

    m_quickBtnList.clear();
    m_quickBtnList.append(ui->buttonQuick1);
    m_quickBtnList.append(ui->buttonQuick2);
    m_quickBtnList.append(ui->buttonQuick3);
    m_quickBtnList.append(ui->buttonQuick4);
    m_quickBtnList.append(ui->buttonQuick5);
    m_quickBtnList.append(ui->buttonQuick6);
    m_quickBtnList.append(ui->buttonQuick7);
    m_quickBtnList.append(ui->buttonQuick8);
    m_quickBtnList.append(ui->buttonQuick9);
    m_quickBtnList.append(ui->buttonQuick10);
    m_quickBtnList.append(ui->buttonQuick11);
    m_quickBtnList.append(ui->buttonQuick12);
    m_quickBtnList.append(ui->buttonQuick13);
    m_quickBtnList.append(ui->buttonQuick14);
    m_quickBtnList.append(ui->buttonQuick15);
    m_quickBtnList.append(ui->buttonQuick16);
    m_quickBtnList.append(ui->buttonQuick17);
    m_quickBtnList.append(ui->buttonQuick18);
    m_quickBtnList.append(ui->buttonQuick19);
    m_quickBtnList.append(ui->buttonQuick20);
    m_quickBtnList.append(ui->buttonQuick21);
    m_quickBtnList.append(ui->buttonQuick22);
    m_quickBtnList.append(ui->buttonQuick23);
    m_quickBtnList.append(ui->buttonQuick24);

    ui->buttonQuick25->setVisible(false);
    ui->buttonQuick26->setVisible(false);
    ui->buttonQuick27->setVisible(false);
    ui->buttonQuick28->setVisible(false);

    for(int i = 0; i < m_quickBtnList.size(); i++)
    {
        connect(m_quickBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotQuickBtnClick())
                );
    }

    m_quickLabelList.clear();
    m_quickLabelList.append(ui->labelQuick1);
    m_quickLabelList.append(ui->labelQuick2);
    m_quickLabelList.append(ui->labelQuick3);
    m_quickLabelList.append(ui->labelQuick4);
    m_quickLabelList.append(ui->labelQuick5);
    m_quickLabelList.append(ui->labelQuick6);
    m_quickLabelList.append(ui->labelQuick7);
    m_quickLabelList.append(ui->labelQuick8);
    m_quickLabelList.append(ui->labelQuick9);
    m_quickLabelList.append(ui->labelQuick10);
    m_quickLabelList.append(ui->labelQuick11);
    m_quickLabelList.append(ui->labelQuick12);
    m_quickLabelList.append(ui->labelQuick13);
    m_quickLabelList.append(ui->labelQuick14);
    m_quickLabelList.append(ui->labelQuick15);
    m_quickLabelList.append(ui->labelQuick16);
    m_quickLabelList.append(ui->labelQuick17);
    m_quickLabelList.append(ui->labelQuick18);
    m_quickLabelList.append(ui->labelQuick19);
    m_quickLabelList.append(ui->labelQuick20);
    m_quickLabelList.append(ui->labelQuick21);
    m_quickLabelList.append(ui->labelQuick22);
    m_quickLabelList.append(ui->labelQuick23);
    m_quickLabelList.append(ui->labelQuick24);

    ui->labelQuick25->setVisible(false);
    ui->labelQuick26->setVisible(false);
    ui->labelQuick27->setVisible(false);
    ui->labelQuick28->setVisible(false);

    m_assistBtnList.clear();
    m_assistBtnList.append(ui->buttonAssist1);
    m_assistBtnList.append(ui->buttonAssist2);
    m_assistBtnList.append(ui->buttonAssist3);
    m_assistBtnList.append(ui->buttonAssist4);
    m_assistBtnList.append(ui->buttonAssist5);
    m_assistBtnList.append(ui->buttonAssist6);
    m_assistBtnList.append(ui->buttonAssist7);
    m_assistBtnList.append(ui->buttonAssist8);
    m_assistBtnList.append(ui->buttonAssist9);
    m_assistBtnList.append(ui->buttonAssist10);
    m_assistBtnList.append(ui->buttonAssist11);
    m_assistBtnList.append(ui->buttonAssist12);
    m_assistBtnList.append(ui->buttonAssist13);
    m_assistBtnList.append(ui->buttonAssist14);
    m_assistBtnList.append(ui->buttonAssist15);
    m_assistBtnList.append(ui->buttonAssist16);
    m_assistBtnList.append(ui->buttonAssist17);
    m_assistBtnList.append(ui->buttonAssist18);
    m_assistBtnList.append(ui->buttonAssist19);
    m_assistBtnList.append(ui->buttonAssist20);
    m_assistBtnList.append(ui->buttonAssist21);
    m_assistBtnList.append(ui->buttonAssist22);
    m_assistBtnList.append(ui->buttonAssist23);
    m_assistBtnList.append(ui->buttonAssist24);

    ui->buttonAssist25->setVisible(false);
    ui->buttonAssist26->setVisible(false);
    ui->buttonAssist27->setVisible(false);
    ui->buttonAssist28->setVisible(false);

    for(int i = 0; i < m_assistBtnList.size(); i++)
    {
        connect(m_assistBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotAssistBtnClick())
                );
    }

    m_assistLabelList.clear();
    m_assistLabelList.append(ui->labelAssist1);
    m_assistLabelList.append(ui->labelAssist2);
    m_assistLabelList.append(ui->labelAssist3);
    m_assistLabelList.append(ui->labelAssist4);
    m_assistLabelList.append(ui->labelAssist5);
    m_assistLabelList.append(ui->labelAssist6);
    m_assistLabelList.append(ui->labelAssist7);
    m_assistLabelList.append(ui->labelAssist8);
    m_assistLabelList.append(ui->labelAssist9);
    m_assistLabelList.append(ui->labelAssist10);
    m_assistLabelList.append(ui->labelAssist11);
    m_assistLabelList.append(ui->labelAssist12);
    m_assistLabelList.append(ui->labelAssist13);
    m_assistLabelList.append(ui->labelAssist14);
    m_assistLabelList.append(ui->labelAssist15);
    m_assistLabelList.append(ui->labelAssist16);
    m_assistLabelList.append(ui->labelAssist17);
    m_assistLabelList.append(ui->labelAssist18);
    m_assistLabelList.append(ui->labelAssist19);
    m_assistLabelList.append(ui->labelAssist20);
    m_assistLabelList.append(ui->labelAssist21);
    m_assistLabelList.append(ui->labelAssist22);
    m_assistLabelList.append(ui->labelAssist23);
    m_assistLabelList.append(ui->labelAssist24);

    ui->labelAssist25->setVisible(false);
    ui->labelAssist26->setVisible(false);
    ui->labelAssist27->setVisible(false);
    ui->labelAssist28->setVisible(false);

    m_patternSetBtnList.clear();
    m_patternSetBtnList.append(ui->buttonPatternSet1);
    m_patternSetBtnList.append(ui->buttonPatternSet2);
    m_patternSetBtnList.append(ui->buttonPatternSet3);
    m_patternSetBtnList.append(ui->buttonPatternSet4);
    m_patternSetBtnList.append(ui->buttonPatternSet5);
    m_patternSetBtnList.append(ui->buttonPatternSet6);
    m_patternSetBtnList.append(ui->buttonPatternSet7);
    m_patternSetBtnList.append(ui->buttonPatternSet8);
    m_patternSetBtnList.append(ui->buttonPatternSet9);
    m_patternSetBtnList.append(ui->buttonPatternSet10);
    m_patternSetBtnList.append(ui->buttonPatternSet11);
    m_patternSetBtnList.append(ui->buttonPatternSet12);
    m_patternSetBtnList.append(ui->buttonPatternSet13);
    m_patternSetBtnList.append(ui->buttonPatternSet14);

    for(int i = 0; i < m_patternSetBtnList.size(); i++)
    {
        connect(m_patternSetBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotPatternSetBtnClick())
                );
    }

    m_patternSetLabelList.append(ui->labelPatternSet1);
    m_patternSetLabelList.append(ui->labelPatternSet2);
    m_patternSetLabelList.append(ui->labelPatternSet3);
    m_patternSetLabelList.append(ui->labelPatternSet4);
    m_patternSetLabelList.append(ui->labelPatternSet5);
    m_patternSetLabelList.append(ui->labelPatternSet6);
    m_patternSetLabelList.append(ui->labelPatternSet7);
    m_patternSetLabelList.append(ui->labelPatternSet8);
    m_patternSetLabelList.append(ui->labelPatternSet9);
    m_patternSetLabelList.append(ui->labelPatternSet10);
    m_patternSetLabelList.append(ui->labelPatternSet11);
    m_patternSetLabelList.append(ui->labelPatternSet12);
    m_patternSetLabelList.append(ui->labelPatternSet13);
    m_patternSetLabelList.append(ui->labelPatternSet14);

    m_paraSetBtnList.clear();
    m_paraSetBtnList.append(ui->buttonParaType1);
    m_paraSetBtnList.append(ui->buttonParaType2);
    m_paraSetBtnList.append(ui->buttonParaType3);
    m_paraSetBtnList.append(ui->buttonParaType4);
    m_paraSetBtnList.append(ui->buttonParaType5);
    m_paraSetBtnList.append(ui->buttonParaType6);
    m_paraSetBtnList.append(ui->buttonParaType7);
    m_paraSetBtnList.append(ui->buttonParaType8);
    m_paraSetBtnList.append(ui->buttonParaType9);
    m_paraSetBtnList.append(ui->buttonParaType10);
    m_paraSetBtnList.append(ui->buttonParaType11);
    m_paraSetBtnList.append(ui->buttonParaType12);
    m_paraSetBtnList.append(ui->buttonParaType13);
    m_paraSetBtnList.append(ui->buttonParaType14);

    for(int i = 0; i < m_paraSetBtnList.size(); i++)
    {
        connect(m_paraSetBtnList.at(i),
                SIGNAL(clicked()),
                this,
                SLOT(slotParaTypeBtnClick())
                );
    }

    m_paraSetLabelList.append(ui->labelParaType1);
    m_paraSetLabelList.append(ui->labelParaType2);
    m_paraSetLabelList.append(ui->labelParaType3);
    m_paraSetLabelList.append(ui->labelParaType4);
    m_paraSetLabelList.append(ui->labelParaType5);
    m_paraSetLabelList.append(ui->labelParaType6);
    m_paraSetLabelList.append(ui->labelParaType7);
    m_paraSetLabelList.append(ui->labelParaType8);
    m_paraSetLabelList.append(ui->labelParaType9);
    m_paraSetLabelList.append(ui->labelParaType10);
    m_paraSetLabelList.append(ui->labelParaType11);
    m_paraSetLabelList.append(ui->labelParaType12);
    m_paraSetLabelList.append(ui->labelParaType13);
    m_paraSetLabelList.append(ui->labelParaType14);

    //根据不同分辨率设置控件的位置和尺寸
    initResolution();
    initControlStyle();//初始化窗体控件样式
}
//初始化窗体控件为任意分辨率
void MainWidget::initResolution()
{
#define TITLE_HEIGHT        (24)      // 标题栏高度
#define STATE_HEIGHT        (36)      // 状态栏高度

    double factoryX = getFactoryX();
    double factoryY = getFactoryY();

    //字体设置
    setViewFont(fontSize_M());

    this->resize(GLB_SCR_WIGHT*factoryX,GLB_SCR_HEIGHT*factoryY);
    {// 标题栏
        ui->frameBack->setGeometry(0*factoryX,0*factoryY,GLB_SCR_WIGHT*factoryX,GLB_SCR_HEIGHT*factoryY);
        ui->frameUp->setGeometry(0*factoryX,0*factoryY,GLB_SCR_WIGHT*factoryX,TITLE_HEIGHT*factoryY);
        ui->buttonMove->setGeometry(0*factoryX,0*factoryY,GLB_SCR_WIGHT*factoryX,TITLE_HEIGHT*factoryY);
        ui->labelTitle->setGeometry(GLB_EDGE_WIGHT*factoryX,(TITLE_HEIGHT - GLB_EDGE_WIGHT)/2*factoryY,
                                    (GLB_SCR_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,TITLE_HEIGHT*factoryY);

        ui->labelHMIVersion->setGeometry(GLB_EDGE_WIGHT*factoryX,(TITLE_HEIGHT - GLB_EDGE_WIGHT)/2*factoryY,
                                         (GLB_SCR_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,TITLE_HEIGHT*factoryY);

    }

    {//下方状态栏
        ui->frameDown->setGeometry(0*factoryX,(GLB_SCR_HEIGHT-STATE_HEIGHT)*factoryY,GLB_SCR_WIGHT*factoryX,STATE_HEIGHT*factoryY);

        ui->labelScreenshot->setGeometry(0*factoryX,0*factoryY,GLB_SCR_WIGHT*factoryX,STATE_HEIGHT*factoryY);//截屏
        ui->labelState->setGeometry(GLB_EDGE_WIGHT*factoryX,0*factoryY,(GLB_SCR_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,STATE_HEIGHT*factoryY);
        ui->labelTime->setGeometry(GLB_EDGE_WIGHT*factoryX,0*factoryY,(GLB_SCR_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,STATE_HEIGHT*factoryY);//时间

        ui->progressBar->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_SCR_WIGHT-2)*factoryY,(GLB_SCR_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,2*factoryY);  // 进度条
        ui->labelWorkState->setGeometry(540*factoryX,0*factoryY,200*factoryX,STATE_HEIGHT*factoryY);//模拟工作
        ui->labelEnableWorkState->setGeometry(780*factoryX,GLB_BAS_WIGHT*factoryY,GLB_SICON_SIZE*factoryX,GLB_SICON_SIZE*factoryY);//显示工作状态
        ui->buttonConnect->setGeometry(770*factoryX,GLB_BAS_WIGHT*factoryY,GLB_SICON_SIZE*factoryX,GLB_SICON_SIZE*factoryY);//链接状态
        ui->buttonUser->setGeometry(790*factoryX,GLB_BAS_WIGHT*factoryY,GLB_SICON_SIZE*factoryX,GLB_SICON_SIZE*factoryY);//用户
        ui->buttonWifi->setGeometry(750*factoryX,GLB_BAS_WIGHT*factoryY,GLB_SICON_SIZE*factoryX,GLB_SICON_SIZE*factoryY);
    }

    {//左侧主按钮
        ui->frameMainFunction->setGeometry(0*factoryX,(TITLE_HEIGHT + GLB_BAS_WIGHT)*factoryY,
                                           (GLB_EDGE_WIGHT+ GLB_LICON_SIZE+GLB_BAS_WIGHT)*factoryX,
                                           (GLB_SCR_HEIGHT - TITLE_HEIGHT-STATE_HEIGHT-GLB_BAS_WIGHT*2)*factoryY);// x坐标 y坐标  宽高

        ui->buttonPatternSet->setGeometry(GLB_EDGE_WIGHT*factoryX,0*factoryY,
                                          GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);//花样设定按钮
        ui->buttonParaSet->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_LICON_SIZE+ GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*1*factoryY,
                                       GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);//参数设定按钮
        ui->buttonShortcutFunction->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_LICON_SIZE+ GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*2*factoryY,
                                                GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);//快捷功能按钮
        ui->buttonAccessFunction->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_LICON_SIZE+ GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*3*factoryY,
                                              GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);//辅助功能按钮
        ui->buttonMainMenu->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_LICON_SIZE+ GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*4*factoryY,
                                        GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);//主界面按钮

        ui->labelPatternSet->setGeometry(GLB_BAS_WIGHT*factoryX,(GLB_LICON_SIZE + GLB_ICON_TEXT)*factoryY,
                                         ((GLB_EDGE_WIGHT-GLB_BAS_WIGHT)*2 + GLB_LICON_SIZE)*factoryX,GLB_TEXT_HEIGHT*factoryY);//花样设定文本框
        ui->labelParaSet->setGeometry(GLB_BAS_WIGHT*factoryX,((GLB_LICON_SIZE + GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*1+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,
                                      ((GLB_EDGE_WIGHT-GLB_BAS_WIGHT)*2 + GLB_LICON_SIZE)*factoryX,GLB_TEXT_HEIGHT*factoryY);//参数设定文本框
        ui->labelShortcutFunction->setGeometry(GLB_BAS_WIGHT*factoryX,((GLB_LICON_SIZE + GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*2+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,
                                               ((GLB_EDGE_WIGHT-GLB_BAS_WIGHT)*2 + GLB_LICON_SIZE)*factoryX,GLB_TEXT_HEIGHT*factoryY);//快捷功能文本框
        ui->labelAccessFunction->setGeometry(GLB_BAS_WIGHT*factoryX,((GLB_LICON_SIZE + GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*3+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,
                                             ((GLB_EDGE_WIGHT-GLB_BAS_WIGHT)*2 + GLB_LICON_SIZE)*factoryX,GLB_TEXT_HEIGHT*factoryY);//辅助功能文本框
        ui->labelMainMenu->setGeometry(GLB_BAS_WIGHT*factoryX,((GLB_LICON_SIZE + GLB_TEXT_HEIGHT + GLB_BAS_WIGHT*2)*4+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,
                                       ((GLB_EDGE_WIGHT-GLB_BAS_WIGHT)*2 + GLB_LICON_SIZE)*factoryX,GLB_TEXT_HEIGHT*factoryY);//主界面文本框
    }


    {//花样显示区域
#define FRAME_LEFT         (102)      // 小窗口
#define FRAME_TOP          (36)
#define FRAME_WIGHT        (654)
#define FRAME_HEIGHT       (512)

#define H_MAX_NUM           (6)       // 横向最大图标数量
#define V_MAX_NUM           (4)       // 纵向最大图标数量

#define ICON_LEFT           ((FRAME_WIGHT - GLB_LICON_SIZE * H_MAX_NUM)/(H_MAX_NUM+1))   // 图标左侧间距
#define ICON_TOP            ((FRAME_HEIGHT - GLB_EDGE_WIGHT - (GLB_LICON_SIZE+GLB_TEXT_HEIGHT*2+GLB_BAS_WIGHT) * V_MAX_NUM)/(V_MAX_NUM+1))   // 图标上侧间距
#define ICON_HEIGHT         (GLB_LICON_SIZE+GLB_TEXT_HEIGHT*2+GLB_BAS_WIGHT+ICON_TOP)   // 图标高度

        int hNum,vNum;

        ui->frameMenuBack->setGeometry(FRAME_LEFT*factoryX,FRAME_TOP*factoryY,FRAME_WIGHT*factoryX,FRAME_HEIGHT*factoryY);//二级菜单的白色背景显示不齐  -rq
        ui->framePatternView->setGeometry(FRAME_LEFT*factoryX,FRAME_TOP*factoryY,FRAME_WIGHT*factoryX,FRAME_HEIGHT*factoryY);
        ui->labelPatternView->setGeometry(GLB_BAS_WIGHT*factoryX,GLB_BAS_WIGHT*factoryY,(FRAME_WIGHT-GLB_BAS_WIGHT*2)*factoryX,(FRAME_HEIGHT-GLB_BAS_WIGHT*2)*factoryY);     //灰色花样图

        {//花样设置
            ui->framePatternSet->setGeometry(FRAME_LEFT*factoryX,FRAME_TOP*factoryY,FRAME_WIGHT*factoryX,FRAME_HEIGHT*factoryY);
            hNum = 6;//每行6个
            vNum = 2;//总共2行
            for(int i = 0; i < vNum; i++)
            {
                for(int j = 0; j < hNum; j++)
                {
                    m_patternSetBtnList[i*hNum+j]->setGeometry((ICON_LEFT+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,(ICON_TOP+ICON_HEIGHT*i)*factoryY,GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);
                    m_patternSetLabelList[i*hNum+j]->setGeometry((ICON_LEFT*2/3+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,((ICON_TOP+ICON_HEIGHT*i)+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,(GLB_LICON_SIZE+ICON_LEFT*2/3)*factoryX,GLB_TEXT_HEIGHT*3*factoryY);
                }
            }
        }

        {//参数设置
            ui->frameParaSet->setGeometry(FRAME_LEFT*factoryX,FRAME_TOP*factoryY,FRAME_WIGHT*factoryX,FRAME_HEIGHT*factoryY);
            hNum = 6;//每行6个
            vNum = 2;//总共2行
            for(int i = 0; i < vNum; i++)
            {
                for(int j = 0; j < hNum; j++)
                {
                    m_paraSetBtnList[i*hNum+j]->setGeometry((ICON_LEFT+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,(ICON_TOP+ICON_HEIGHT*i)*factoryY,GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);
                    m_paraSetLabelList[i*hNum+j]->setGeometry((ICON_LEFT*2/3+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,((ICON_TOP+ICON_HEIGHT*i)+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,(GLB_LICON_SIZE+ICON_LEFT*2/3)*factoryX,GLB_TEXT_HEIGHT*3*factoryY);
                }
            }
        }

        {//快捷功能
            ui->frameShortcutFunction->setGeometry(FRAME_LEFT*factoryX,FRAME_TOP*factoryY,FRAME_WIGHT*factoryX,FRAME_HEIGHT*factoryY);//(108,36,707,513)
            hNum = 6;//每行6个
            vNum = 4;//总共4行
            for(int i = 0; i < vNum; i++)
            {
                for(int j = 0; j < hNum; j++)
                {
                    m_quickBtnList[i*hNum+j]->setGeometry((ICON_LEFT+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,(ICON_TOP+ICON_HEIGHT*i)*factoryY,GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);
                    m_quickLabelList[i*hNum+j]->setGeometry((ICON_LEFT*2/3+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,((ICON_TOP+ICON_HEIGHT*i)+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,(GLB_LICON_SIZE+ICON_LEFT*2/3)*factoryX,GLB_TEXT_HEIGHT*3*factoryY);
                }
            }
            ui->buttonShortCutPgUp->setGeometry(426*factoryX,465*factoryY,80*factoryX,30*factoryY);
            ui->buttonShortCutPgDn->setGeometry(536*factoryX,465*factoryY,80*factoryX,30*factoryY);
            ui->labelShortCutPage->setGeometry(326*factoryX,465*factoryY,80*factoryX,30*factoryY);
            ui->buttonAssistPgUp->setGeometry(426*factoryX,465*factoryY,80*factoryX,30*factoryY);
            ui->buttonAssistPgDn->setGeometry(536*factoryX,465*factoryY,80*factoryX,30*factoryY);
            ui->labelAssistPage->setGeometry(326*factoryX,465*factoryY,80*factoryX,30*factoryY);
        }

        {//辅助功能
            ui->frameAccessFunction->setGeometry(FRAME_LEFT*factoryX,FRAME_TOP*factoryY,FRAME_WIGHT*factoryX,FRAME_HEIGHT*factoryY);
            hNum = 6;//每行6个
            vNum = 4;//总共4行
            for(int i = 0; i < vNum; i++)
            {
                for(int j = 0; j < hNum; j++)
                {
                    m_assistBtnList[i*hNum+j]->setGeometry((ICON_LEFT+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,(ICON_TOP+ICON_HEIGHT*i)*factoryY,GLB_LICON_SIZE*factoryX,GLB_LICON_SIZE*factoryY);
                    m_assistLabelList[i*hNum+j]->setGeometry((ICON_LEFT*2/3+(ICON_LEFT+GLB_LICON_SIZE)*j)*factoryX,((ICON_TOP+ICON_HEIGHT*i)+(GLB_LICON_SIZE + GLB_ICON_TEXT))*factoryY,(GLB_LICON_SIZE+ICON_LEFT*2/3)*factoryX,GLB_TEXT_HEIGHT*3*factoryY);//字体显示不全  -rq
                }
            }
        }
    }

    {//右上方花样信息
#define INFO_LEFT         (772)
#define INFO_TOP          (36)
#define INFO_WIGHT        (235)
#define INFO_HEIGHT       (262)

        ui->frameEmbInfo->setGeometry(INFO_LEFT*factoryX,INFO_TOP*factoryY,INFO_WIGHT*factoryX,INFO_HEIGHT*factoryY);
        initPatternInfo(GLB_BAS_WIGHT*factoryX, GLB_BAS_WIGHT*factoryY, (INFO_WIGHT-GLB_BAS_WIGHT*2)*factoryX, (GLB_TEXT_HEIGHT+GLB_BAS_WIGHT)*factoryY);
    }

    {//九宫格
#define NINE_LEFT       (772)
#define NINE_TOP        (312)
#define NINE_WIGHT      (235)
#define NINE_HEIGHT     (235)

#define NINE_BUT_SIZE   (70)      // 九宫格按尺寸
#define NINE_BAS_WIGHT   ((NINE_WIGHT - NINE_BUT_SIZE*3) /2)

#define LED_W          (42)      // 数码管宽
#define LED_H          (56)      // 数码管高

        ui->frameFunctionBtn->setGeometry(NINE_LEFT*factoryX,
                                          NINE_TOP*factoryY,
                                          NINE_WIGHT*factoryX,
                                          NINE_HEIGHT*factoryY);// x y w h

        ui->frameSpeed->setGeometry(0*factoryX,0*factoryY,
                                    NINE_WIGHT*factoryX,
                                    NINE_HEIGHT*factoryY);

        ui->labelSpeed->setGeometry(0*factoryX,0*factoryY,
                                    NINE_WIGHT *factoryX,
                                    NINE_BUT_SIZE*factoryY);//显示机器运行速度的数字的数码管

        int ledL = (NINE_WIGHT-(LED_W*4))/2;
        int ledT = (NINE_BUT_SIZE-LED_H)/2;

        ui->labelSpeed1->setGeometry(ledL*factoryX,ledT*factoryY,LED_W*factoryX,LED_H*factoryY);
        ui->labelSpeed2->setGeometry((ledL+LED_W)*factoryX,ledT*factoryY,LED_W*factoryX,LED_H*factoryY);
        ui->labelSpeed3->setGeometry((ledL+LED_W*2)*factoryX,ledT*factoryY,LED_W*factoryX,LED_H*factoryY);
        ui->labelSpeed4->setGeometry((ledL+LED_W*3)*factoryX,ledT*factoryY,LED_W*factoryX,LED_H*factoryY);

        ui->buttonSpeedDec->setGeometry(0*factoryX,(NINE_BAS_WIGHT + NINE_BUT_SIZE)*factoryY,
                                        (NINE_WIGHT - NINE_BAS_WIGHT)/2*factoryX,
                                        (NINE_BUT_SIZE-NINE_BAS_WIGHT)*factoryY);

        ui->buttonSpeedAdd->setGeometry(((NINE_WIGHT - NINE_BAS_WIGHT)/2 + NINE_BAS_WIGHT)*factoryX,
                                        (NINE_BAS_WIGHT + NINE_BUT_SIZE)*factoryY,
                                        (NINE_WIGHT - NINE_BAS_WIGHT)/2*factoryX,
                                        (NINE_BUT_SIZE-NINE_BAS_WIGHT)*factoryY);

        ui->buttonStartStop->setGeometry(0*factoryX,
                                         (NINE_BAS_WIGHT + NINE_BUT_SIZE*2)*factoryY,
                                         NINE_WIGHT*factoryX,
                                         (NINE_BUT_SIZE+NINE_BAS_WIGHT)*factoryY);

        ui->frameSpeed->hide();
        ui->labelSpeed->hide();
        ui->labelSpeed1->hide();
        ui->labelSpeed2->hide();
        ui->labelSpeed3->hide();
        ui->labelSpeed4->hide();
        ui->buttonSpeedAdd->hide();
        ui->buttonSpeedDec->hide();
        ui->buttonStartStop->hide();
        ui->frameNineBtn->setGeometry(0*factoryX,0*factoryY,236*factoryX,236*factoryY);

#define GAP_X  (NINE_BUT_SIZE + NINE_BAS_WIGHT)
#define GAP_Y  (NINE_BUT_SIZE + NINE_BAS_WIGHT)
        ui->buttonNineBtn1->setGeometry(0*factoryX,0*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtnUp->setGeometry(GAP_X*factoryX,0*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtn2->setGeometry(GAP_X*2*factoryX,0*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtnLeft->setGeometry(0*factoryX,GAP_Y*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtnMiddle->setGeometry(GAP_X*factoryX,GAP_Y*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtnRight->setGeometry(GAP_X*2*factoryX,GAP_Y*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtn3->setGeometry(0*factoryX,GAP_Y*2*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtnDown->setGeometry(GAP_X*factoryX,GAP_Y*2*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
        ui->buttonNineBtn4->setGeometry(GAP_X*2*factoryX,GAP_Y*2*factoryY,NINE_BUT_SIZE*factoryX,NINE_BUT_SIZE*factoryY);
    }

    {//快进回退
#define JUMP_LEFT         (772)      // 小窗口
#define JUMP_TOP          (36)
#define JUMP_WIGHT        (235)
#define JUMP_HEIGHT       (512)

        ui->frameForwardBack->setGeometry(JUMP_LEFT*factoryX,JUMP_TOP*factoryY,JUMP_WIGHT*factoryX,JUMP_HEIGHT*factoryY);
        ui->frameForwardBackBack->setGeometry(0*factoryX,0*factoryY,JUMP_WIGHT*factoryX,JUMP_HEIGHT*factoryY);
        ui->buttonNeedleIdxImage->setGeometry(23*factoryX,45*factoryY,8*factoryX,25*factoryY);
        ui->labelForwardBackTitle->setGeometry(GLB_EDGE_WIGHT*factoryX,GLB_EDGE_WIGHT*factoryY,(JUMP_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,GLB_TEXT_L_HEIGHT*factoryY);
        ui->labelNeedleCurAndTotal->setGeometry(GLB_EDGE_WIGHT*factoryX,(GLB_EDGE_WIGHT+GLB_BAS_WIGHT+GLB_TEXT_L_HEIGHT)*factoryY,(JUMP_WIGHT-GLB_EDGE_WIGHT*2)*factoryX,GLB_TEXT_HEIGHT*factoryY);

#define JUMP_BUTFAR_HEIGHT (420)        // 按钮区域高度
#define JUMP_BUTFAR_TOP    (JUMP_HEIGHT-JUMP_BUTFAR_HEIGHT)

#define JUMP_BUT_WIGHT    GLB_MBUT_WIGHT
#define JUMP_BUT_HEIGHT   GLB_MBUT_HEIGHT

#define JUMP_BUT_GAP_X   ((JUMP_WIGHT - JUMP_BUT_WIGHT*2)/3)
#define JUMP_BUT_GAP_Y   ((JUMP_BUTFAR_HEIGHT - JUMP_BUT_HEIGHT*8)/10)

        ui->buttonNeedleBegin->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*0)*factoryY,
                                           JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonNeedleEnd->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*0)*factoryY,
                                         JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonNeedleDec1->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*1)*factoryY,
                                          JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonNeedleAdd1->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*1)*factoryY,
                                          JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonNeedleDec10->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*2)*factoryY,
                                           JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonNeedleAdd10->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*2)*factoryY,
                                           JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonNeedleDec100->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*3)*factoryY,
                                            JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonNeedleAdd100->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*3)*factoryY,
                                            JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonNeedleDec1000->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*4)*factoryY,
                                             JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonNeedleAdd1000->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*4)*factoryY,
                                             JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonNeedleDec10000->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*5)*factoryY,
                                              JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonNeedleAdd10000->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*5)*factoryY,
                                              JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonElementDec->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*6)*factoryY,
                                          JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonElementAdd->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*6)*factoryY,
                                          JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);

        ui->buttonForwardBackOk->setGeometry(JUMP_BUT_GAP_X*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*7)*factoryY,
                                             JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
        ui->buttonForwardBackCancel->setGeometry((JUMP_BUT_GAP_X*2+JUMP_BUT_WIGHT)*factoryX,(JUMP_BUTFAR_TOP+JUMP_BUT_GAP_Y+JUMP_BUT_GAP_Y+(JUMP_BUT_GAP_Y+JUMP_BUT_HEIGHT)*7)*factoryY,
                                                 JUMP_BUT_WIGHT*factoryX,JUMP_BUT_HEIGHT*factoryY);
    }
}

//初始化窗体控件样式
void MainWidget::initControlStyle()
{
    //上状态栏时间
    ui->labelTime->setStyleSheet(titleTextColour());
    ui->labelTime->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
    ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Unconnect"));

    //背景透明
    ui->frameUp->setStyleSheet(transparentStyle());
    ui->frameMainFunction->setStyleSheet(transparentStyle());
    ui->frameAccessFunction->setStyleSheet(transparentStyle());
    ui->framePatternSet->setStyleSheet(transparentStyle());
    ui->frameShortcutFunction->setStyleSheet(transparentStyle());
    ui->frameParaSet->setStyleSheet(transparentStyle());
    ui->frameDown->setStyleSheet(transparentStyle());
    ui->frameEmbInfo->setStyleSheet(transparentStyle());

    ui->framePatternView->setStyleSheet(transparentStyle());
    ui->frameFunctionBtn->setStyleSheet(transparentStyle());
    QString style = "background-color: rgb(246, 242, 239);outline:none;border:0px;border-radius:" + borderRadius() + "px;";
    ui->frameMenuBack->setStyleSheet(style);

    //设置控件图标
    //背景图
    int waterMark = g_pSettings->readFromIniFile("HMI/waterMark").toInt();//是否带水印
    QString backGroundImgPath;
    if(waterMark == 1)
    {
        backGroundImgPath = m_setControlStyle.getBorderImageStyleSheet(this->objectName());
    }
    else if(waterMark == 0)
    {
        backGroundImgPath = m_setControlStyle.getBorderImageStyleSheet(this->objectName() + "_NoWaterMark");
        qDebug()<<backGroundImgPath;
    }
    ui->frameBack->setStyleSheet(backGroundImgPath);
    if(g_emDebugMode == debugMode)
    {
        ui->labelTitle->setText(tr("Debugging mode, prohibit sending machine!"));//调试模式,禁止发机!!
        ui->labelTitle->setStyleSheet(warnTextColour());
    }
    else
    {
        if(waterMark==1)//带logo
        {
            ui->labelTitle->setStyleSheet(titleTextColour());
        }
        else
        {
            ui->labelTitle->setStyleSheet(titleTextColour());
        }
    }

    //获得绘制区域的背景图，用于embdata绘制刷新图形时的背景
    int x = ui->labelPatternView->x() + ui->framePatternView->x();
    int y = ui->labelPatternView->y() + ui->framePatternView->y();
    QImage MainWidgetPix;
    MainWidgetPix.load(getBackImagePath(waterMark));//主界面背景图
    if(g_emResolut == resolution0804){
        x +=15;
    }

    //从主界面背景图截取等于labelPatternView的背景图
    m_embBackPix = QPixmap(ui->labelPatternView->width(),ui->labelPatternView->height());
    m_embBackPix = QPixmap::fromImage(MainWidgetPix.copy(x,y,m_embBackPix.width(),m_embBackPix.height()));

    //状态图标
    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Unconnected"));
    ui->buttonUser->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonUser->objectName()));

    //主功能键图标
    ui->labelMainMenu->setStyleSheet(mainIconTextColour());
    ui->labelPatternSet->setStyleSheet(mainIconTextColour());
    ui->labelAccessFunction->setStyleSheet(mainIconTextColour());
    ui->labelParaSet->setStyleSheet(mainIconTextColour());
    ui->labelShortcutFunction->setStyleSheet(mainIconTextColour());

    //ui->buttonMainMenu->setCheckedBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonMainMenu->parent()->objectName()));
    ui->buttonMainMenu->setStyleSheet(mainIconStyle());
    ui->buttonMainMenu->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonMainMenu->objectName()));
    ui->buttonPatternSet->setStyleSheet(mainIconStyle());
    ui->buttonPatternSet->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonPatternSet->objectName()));
    ui->buttonAccessFunction->setStyleSheet(mainIconStyle());
    ui->buttonAccessFunction->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonAccessFunction->objectName()));
    ui->buttonParaSet->setStyleSheet(mainIconStyle());
    ui->buttonParaSet->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonParaSet->objectName()));
    ui->buttonShortcutFunction->setStyleSheet(mainIconStyle());
    ui->buttonShortcutFunction->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonShortcutFunction->objectName()));

    //速度加减图标
    ui->labelSpeed->setStyleSheet(m_setControlStyle.getStyleSheet("labelSpeed"));
    ui->buttonStartStop->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonStartStop->objectName()));
    ui->buttonStartStop->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonStartStop->objectName()));
    ui->buttonSpeedAdd->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonSpeedAdd->objectName()));
    ui->buttonSpeedAdd->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonSpeedAdd->objectName()));
    ui->buttonSpeedDec->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonSpeedDec->parent()->objectName()));
    ui->buttonSpeedDec->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonSpeedDec->objectName()));
    ui->buttonSpeedDec->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonSpeedDec->objectName()));

    //绣作信息
    ui->lab_FileName->setText(tr("File")); //文件
    ui->lab_Index->setText(tr("Idx"));  //索引
    ui->lab_Schedule->setText(tr("Sched"));  //进度
    ui->lab_StartPoint->setText(tr("StartPos")); // 起始点
    ui->lab_Locate->setText(tr("LocPos")); // 定位点
    ui->lab_Range->setText(tr("RG")); // 范围
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        ui->lab_Position->setText(tr("BobbinLen"));  //底线长度
    }
    else
    {
        ui->lab_Position->setText(tr("Pos"));  //位置
    }

    ui->lab_Production->setText(tr("Prod")); //产量
    ui->lab_FileName->setAlignment(Qt::AlignLeft);
    ui->lab_Index->setAlignment(Qt::AlignLeft);
    ui->lab_StartPoint->setAlignment(Qt::AlignLeft);
    ui->lab_Locate->setAlignment(Qt::AlignLeft);
    ui->lab_Range->setAlignment(Qt::AlignLeft);
    ui->lab_Position->setAlignment(Qt::AlignLeft);
    ui->lab_Production->setAlignment(Qt::AlignLeft);
    ui->lab_Schedule->setAlignment(Qt::AlignLeft);
    ui->lab_FileName_2->setAlignment(Qt::AlignRight);
    ui->lab_Index_2->setAlignment(Qt::AlignRight);
    ui->lab_StartPoint_2->setAlignment(Qt::AlignRight);
    ui->lab_Locate_2->setAlignment(Qt::AlignRight);
    ui->lab_Range_2->setAlignment(Qt::AlignRight);
    ui->lab_Position_2->setAlignment(Qt::AlignRight);
    ui->lab_Production_2->setAlignment(Qt::AlignRight);
    ui->lab_Schedule_2->setAlignment(Qt::AlignRight);

    ui->lab_FileName->setStyleSheet(stateTextColour());
    ui->lab_Index->setStyleSheet(stateTextColour());
    ui->lab_StartPoint->setStyleSheet(stateTextColour());
    ui->lab_Locate->setStyleSheet(stateTextColour());
    ui->lab_Range->setStyleSheet(stateTextColour());
    ui->lab_Position->setStyleSheet(stateTextColour());
    ui->lab_Production->setStyleSheet(stateTextColour());
    ui->lab_FileName_2->setStyleSheet(stateTextColour());
    ui->lab_Index_2->setStyleSheet(stateTextColour());
    ui->lab_StartPoint_2->setStyleSheet(stateTextColour());
    ui->lab_Locate_2->setStyleSheet(stateTextColour());
    ui->lab_Range_2->setStyleSheet(stateTextColour());
    ui->lab_Position_2->setStyleSheet(stateTextColour());
    ui->lab_Production_2->setStyleSheet(stateTextColour());
    ui->lab_Schedule->setStyleSheet(stateTextColour());
    ui->lab_Schedule_2->setStyleSheet(stateTextColour());

    //九宫格图标
    ui->buttonNineBtnUp->setBottomImage(m_setControlStyle.getBottomStyleSheet("buttonNineBtn"));
    ui->buttonNineBtnDown->setBottomImage(m_setControlStyle.getBottomStyleSheet("buttonNineBtn"));
    ui->buttonNineBtnLeft->setBottomImage(m_setControlStyle.getBottomStyleSheet("buttonNineBtn"));
    ui->buttonNineBtnMiddle->setBottomImage(m_setControlStyle.getBottomStyleSheet("buttonNineBtn"));
    ui->buttonNineBtnRight->setBottomImage(m_setControlStyle.getBottomStyleSheet("buttonNineBtn"));

    ui->buttonNineBtnUp->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtnUp->objectName()));
    ui->buttonNineBtnDown->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtnDown->objectName()));
    ui->buttonNineBtnLeft->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtnLeft->objectName()));
    ui->buttonNineBtnMiddle->setTopImage(m_setControlStyle.getTopStyleSheet("frameNineBtnMiddle_2"));//默认速度等级为2
    ui->buttonNineBtnRight->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtnRight->objectName()));


    ui->buttonNineBtn1->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonNineBtn1->parent()->objectName()));
    ui->buttonNineBtn2->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonNineBtn2->parent()->objectName()));
    ui->buttonNineBtn3->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonNineBtn3->parent()->objectName()));
    ui->buttonNineBtn4->setBottomImage(m_setControlStyle.getBottomStyleSheet(ui->buttonNineBtn4->parent()->objectName()));

    ui->buttonNineBtn1->setTopImage(m_setControlStyle.getTopStyleSheet(m_nineBtn.value(1).m_topImageName));
    ui->buttonNineBtn2->setTopImage(m_setControlStyle.getTopStyleSheet(m_nineBtn.value(2).m_topImageName));
    ui->buttonNineBtn3->setTopImage(m_setControlStyle.getTopStyleSheet(m_nineBtn.value(3).m_topImageName));
    ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(m_nineBtn.value(4).m_topImageName));

    //快进快退
    ui->frameForwardBack->setStyleSheet(transparentStyle());
    QString frameForwardBackBackImgPath = m_setControlStyle.getStyleSheet(ui->frameForwardBackBack->objectName());

    ui->frameForwardBackBack->setStyleSheet(frameForwardBackBackImgPath);
    ui->labelForwardBackTitle->setStyleSheet(titleTextColour());
    ui->labelForwardBackTitle->setFont(fontSize_L());
    ui->labelNeedleCurAndTotal->setStyleSheet(titleTextColour());
    ui->labelNeedleCurAndTotal->setAlignment(Qt::AlignRight);
    ui->buttonNeedleBegin->setStyleSheet(numButtonStyle());
    ui->buttonNeedleEnd->setStyleSheet(numButtonStyle());
    ui->buttonNeedleAdd1->setStyleSheet(numButtonStyle());
    ui->buttonNeedleDec10000->setStyleSheet(numButtonStyle());
    ui->buttonNeedleAdd10->setStyleSheet(numButtonStyle());
    ui->buttonNeedleAdd100->setStyleSheet(numButtonStyle());
    ui->buttonNeedleAdd1000->setStyleSheet(numButtonStyle());
    ui->buttonNeedleAdd10000->setStyleSheet(numButtonStyle());
    ui->buttonNeedleDec1->setStyleSheet(numButtonStyle());
    ui->buttonNeedleDec10->setStyleSheet(numButtonStyle());
    ui->buttonNeedleDec100->setStyleSheet(numButtonStyle());
    ui->buttonNeedleDec1000->setStyleSheet(numButtonStyle());
    ui->buttonElementDec->setStyleSheet(numButtonStyle());
    ui->buttonElementAdd->setStyleSheet(numButtonStyle());

    if(g_emMacType != MACHINE_FIVEHEADPRECISIONSEWING)
    {
        ui->buttonElementDec->setVisible(false);
        ui->buttonElementAdd->setVisible(false);
    }

    //    ui->buttonNeedleBegin->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleBegin->objectName()));
    //    ui->buttonNeedleEnd->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleEnd->objectName()));
    //    ui->buttonNeedleAdd1->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd1->objectName()));
    //    ui->buttonNeedleAdd10->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd10->objectName()));
    //    ui->buttonNeedleAdd100->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd100->objectName()));
    //    ui->buttonNeedleAdd1000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd1000->objectName()));
    //    ui->buttonNeedleAdd10000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleAdd10000->objectName()));
    //    ui->buttonNeedleDec1->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec1->objectName()));
    //    ui->buttonNeedleDec10->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec10->objectName()));
    //    ui->buttonNeedleDec100->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec100->objectName()));
    //    ui->buttonNeedleDec1000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec1000->objectName()));
    //    ui->buttonNeedleDec10000->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNeedleDec10000->objectName()));
    //    ui->buttonElementDec->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonElementDec->objectName()));
    //    ui->buttonElementAdd->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonElementAdd->objectName()));

    ui->buttonForwardBackOk->setStyleSheet(confirmIconStyle());
    ui->buttonForwardBackOk->setTopImage(m_setControlStyle.getSharedTopStyleSheet("buttonOk"),0,5,0,0);
    ui->buttonForwardBackCancel->setStyleSheet(confirmIconStyle());
    ui->buttonForwardBackCancel->setTopImage(m_setControlStyle.getSharedTopStyleSheet("buttonCancel"),0,5,0,0);

    //花样设置功能图标
    for(int i = 0; i < m_patternSetLabelList.size(); i++)
    {
        m_patternSetLabelList[i]->setWordWrap(true);
        m_patternSetLabelList[i]->setAlignment((Qt::AlignTop|Qt::AlignHCenter));
        //底图相同
        m_patternSetBtnList[i]->setStyleSheet(classIconStyle());
    }

    //参数设置功能图标
    for(int i = 0; i < m_paraSetLabelList.size(); i++)
    {
        m_paraSetLabelList[i]->setWordWrap(true);
        m_paraSetLabelList[i]->setAlignment((Qt::AlignTop|Qt::AlignHCenter));
        //底图相同
        m_paraSetBtnList[i]->setStyleSheet(classIconStyle());
    }

    //快捷功能图标
    for(int i = 0; i < m_quickLabelList.size(); i++)
    {
        m_quickLabelList[i]->setWordWrap(true);
        m_quickLabelList[i]->setAlignment((Qt::AlignTop|Qt::AlignHCenter));
        //28个快捷按钮的底图相同
        m_quickBtnList[i]->setStyleSheet(classIconStyle());
    }

    //辅助功能图标
    for(int i = 0; i < m_assistLabelList.size(); i++)
    {
        m_assistLabelList[i]->setWordWrap(true);
        m_assistLabelList[i]->setAlignment((Qt::AlignTop|Qt::AlignHCenter));
        //28个快捷按钮的底图相同
        m_assistBtnList[i]->setStyleSheet(classIconStyle());
    }

    ui->buttonShortCutPgUp->setStyleSheet(flippingStyle());
    ui->buttonShortCutPgDn->setStyleSheet(flippingStyle());
    ui->buttonShortCutPgUp->setFont(fontSize_M());
    ui->buttonShortCutPgDn->setFont(fontSize_M());

    ui->buttonAssistPgUp->setStyleSheet(flippingStyle());
    ui->buttonAssistPgDn->setStyleSheet(flippingStyle());
    ui->buttonAssistPgUp->setFont(fontSize_M());
    ui->buttonAssistPgDn->setFont(fontSize_M());

    ui->labelAssistPage->setFont(fontSize_S());
    ui->labelShortCutPage->setFont(fontSize_S());

    //下方状态及版本
    ui->progressBar->setStyleSheet(progressStyle());
    ui->progressBar->setValue(0);
    ui->labelState->setStyleSheet(titleTextColour());
    ui->labelState->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
    ui->labelWorkState->setFont(fontSize_M());
    ui->labelWorkState->setStyleSheet(titleTextColour());
    ui->labelWorkState->setAlignment(Qt::AlignCenter);
    ui->labelHMIVersion->setStyleSheet(titleTextColour());

}

//获取背景图的加载路径
QString MainWidget::getBackImagePath(s16 waterMark)
{
    //<分辨率><主题><窗体名称><图片名称>
    QString path = ":/images/";

    //分辨率
    QString str;
    str.clear();
    switch (g_emResolut)
    {
    case resolution1910:
        str = "_1910_logo.png";
        break;
    case resolution1006:
        str = "_1006_logo.png";
        break;
    case resolution0804:
        str = "_1006_logo.png";
        break;
    default:
        break;
    }

    path += this->objectName() + "/" + this->objectName();
    if(waterMark == 0)//无水印
    {
        path += "_NoWaterMark" + str;
    }
    else
    {
        path += str;
    }

    //qDebug()<<path;
    return path;
}

//用数字管显示速度
void MainWidget::showWorkSpeed(QString speed)
{
    int speedsize;//速度数字的位数
    speedsize = speed.size();

    for(int i = 0; i < speedsize; i++)
    {
        QString getnum;
        getnum = speed.mid(i,1);
        if (getnum < "0" || getnum > "9")
        {
            return;
        }
    }

    SetStyle setControlStyle;
    setControlStyle.setUiName(this->objectName());
    //ui->labelScreenshot->setStyleSheet(setControlStyle.getStyleSheet("labelScreenshot"));

    if(speedsize == 1)//如果是一位数
    {//4显示
        ui->labelSpeed1->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        ui->labelSpeed2->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        ui->labelSpeed3->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        QString getnum;
        getnum = speed.mid(0,1);
        QString str_label_3 = "Speed" + getnum;
        ui->labelSpeed4->setStyleSheet(setControlStyle.getStyleSheet(str_label_3));

    }
    else if (speedsize == 2)//如果是2位
    {//3,4显示
        ui->labelSpeed1->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        ui->labelSpeed2->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        QString getnum;
        getnum = speed.mid(0,1); //十位
        QString str_label_2 = "Speed" + getnum;
        ui->labelSpeed3->setStyleSheet(setControlStyle.getStyleSheet(str_label_2));

        getnum = speed.mid(1,1); //个位
        QString str_label_3 = "Speed" + getnum;
        ui->labelSpeed4->setStyleSheet(setControlStyle.getStyleSheet(str_label_3));
    }
    else if (speedsize == 3)
    {
        ui->labelSpeed1->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));

        QString getnum;
        getnum = speed.mid(0,1); //百位
        QString str_label_2 = "Speed" + getnum;
        ui->labelSpeed2->setStyleSheet(setControlStyle.getStyleSheet(str_label_2));

        getnum = speed.mid(1,1); //十位
        QString str_label_3 = "Speed" + getnum;
        ui->labelSpeed3->setStyleSheet(setControlStyle.getStyleSheet(str_label_3));

        getnum = speed.mid(2,1); //个位
        QString str_label_4 = "Speed" + getnum;
        ui->labelSpeed4->setStyleSheet(setControlStyle.getStyleSheet(str_label_4));

    }
    else if (speedsize == 4)//如果是4位数
    {
        QString getnum;

        getnum = speed.mid(0,1); //百位
        QString str_label_1 = "Speed" + getnum;
        ui->labelSpeed1->setStyleSheet(setControlStyle.getStyleSheet(str_label_1));

        getnum = speed.mid(1,1); //百位
        QString str_label_2 = "Speed" + getnum;
        ui->labelSpeed2->setStyleSheet(setControlStyle.getStyleSheet(str_label_2));

        getnum = speed.mid(2,1); //十位
        QString str_label_3 = "Speed" + getnum;
        ui->labelSpeed3->setStyleSheet(setControlStyle.getStyleSheet(str_label_3));

        getnum = speed.mid(3,1); //个位
        QString str_label_4 = "Speed" + getnum;
        ui->labelSpeed4->setStyleSheet(setControlStyle.getStyleSheet(str_label_4));
    }
    else
    {
        ui->labelSpeed1->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        ui->labelSpeed2->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        ui->labelSpeed3->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
        ui->labelSpeed4->setStyleSheet(setControlStyle.getStyleSheet("SpeedShut"));
    }
}

void MainWidget::setViewFont(QFont font)
{
    //字体设置
    ui->labelTime->setFont(font);
    ui->labelMainMenu->setFont(font);
    ui->labelPatternSet->setFont(font);
    ui->labelAccessFunction->setFont(font);
    ui->labelParaSet->setFont(font);
    ui->labelShortcutFunction->setFont(font);
    ui->lab_FileName_2->setFont(font);
    ui->lab_Index_2->setFont(font);
    ui->lab_StartPoint_2->setFont(font);
    ui->lab_Locate_2->setFont(font);
    ui->lab_Range_2->setFont(font);
    ui->lab_Position_2->setFont(font);
    ui->lab_Schedule->setFont(font);
    ui->lab_Schedule_2->setFont(font);
    ui->lab_Production_2->setFont(font);
    ui->lab_FileName->setFont(font);
    ui->lab_Index->setFont(font);
    ui->lab_StartPoint->setFont(font);
    ui->lab_Locate->setFont(font);
    ui->lab_Range->setFont(font);
    ui->lab_Position->setFont(font);
    ui->lab_Production->setFont(font);
    ui->labelForwardBackTitle->setFont(font);
    ui->labelNeedleCurAndTotal->setFont(font);
    ui->labelTitle->setFont(font);
    //快捷功能图标
    for(int i = 0; i < m_quickLabelList.size(); i++)
    {
        m_quickLabelList[i]->setFont(font);
        m_quickLabelList[i]->setStyleSheet(classIconTextColour());
    }

    //辅助功能图标
    for(int i = 0; i < m_assistLabelList.size(); i++)
    {
        m_assistLabelList[i]->setFont(font);
        m_assistLabelList[i]->setStyleSheet(classIconTextColour());
    }

    //花样设置功能图标
    for(int i = 0; i < m_patternSetLabelList.size(); i++)
    {
        m_patternSetLabelList[i]->setFont(font);
        m_patternSetLabelList[i]->setStyleSheet(classIconTextColour());
    }

    //参数设置功能图标
    for(int i = 0; i < m_paraSetLabelList.size(); i++)
    {
        m_paraSetLabelList[i]->setFont(font);
        m_paraSetLabelList[i]->setStyleSheet(classIconTextColour());
    }
    ui->labelState->setFont(font);
    ui->labelHMIVersion->setFont(font);
}

void MainWidget::refreshPageUi(s16 type)
{
    if(m_itemPerPage <= 0)//界面每页按钮数
    {
        return;
    }

    //-----------
    int itemNum, pageNums;
    itemNum = pageNums = 0;

    if(type == INTERFACE_SHORTCUT)
    {
        itemNum = m_quickItemList.size();//快捷功能列表
    }
    else if(type == INTERFACE_ACCESS)
    {
        itemNum = m_assistItemList.size();//辅助功能列表
    }

    pageNums = (itemNum+m_itemPerPage-1) / m_itemPerPage;//计算总页数

    if (m_curPages > pageNums)                 // 当前页
    {
        m_curPages = pageNums;
    }
    if (m_curPages <= 1)
    {
        m_curPages = 1;
    }

    // 刷新文本和图标
    int i, itemidx;
    itemidx = (m_curPages-1) * m_itemPerPage;
    for (i = 0; i < m_itemPerPage; i++)
    {
        if (itemidx < itemNum)    //itemNum   从绣花参数一共有的按钮功能，可以是28+个
        {
            if(type == INTERFACE_SHORTCUT)
            {
                QString name = m_quickItemList[itemidx].m_name;
                m_quickLabelList[i]->setText(name);
                m_quickLabelList.at(i)->show();//名称

                QString topImageName = m_quickItemList[itemidx].m_topImageName;
                //加载按钮顶图图标
                QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
                m_quickBtnList[i]->setTopImage(btnStyle);
                m_quickBtnList.at(i)->show();
            }
            else if(type == INTERFACE_ACCESS)
            {
                QString name = m_assistItemList[itemidx].m_name;
                m_assistLabelList[i]->setText(name);
                m_assistLabelList.at(i)->show();//名称

                QString topImageName = m_assistItemList[itemidx].m_topImageName;
                //加载按钮顶图图标
                QString btnStyle = m_setControlStyle.getTopStyleSheet(topImageName);
                m_assistBtnList[i]->setTopImage(btnStyle);
                m_assistBtnList.at(i)->show();
            }
        }
        else
        {
            if(type == INTERFACE_SHORTCUT)
            {
                m_quickBtnList.at(i)->hide();//按钮
                m_quickLabelList.at(i)->hide();//名称
            }
            else if(type == INTERFACE_ACCESS)
            {
                m_assistBtnList.at(i)->hide();//按钮
                m_assistLabelList.at(i)->hide();//名称
            }
        }
        itemidx++;
    }

    // 刷新按钮
    if (m_curPages <= 1)
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgUp->setEnabled(false);
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgUp->setEnabled(false);
        }
    }
    else
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgUp->setEnabled(true);//上一页按钮显示
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgUp->setEnabled(true);
        }
    }
    if (m_curPages >= pageNums)//当前页大于等于总页数
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgDn->setEnabled(false);
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgDn->setEnabled(false);
        }
    }
    else
    {
        if(type == INTERFACE_SHORTCUT)
        {
            ui->buttonShortCutPgDn->setEnabled(true);
        }
        else if(type == INTERFACE_ACCESS)
        {
            ui->buttonAssistPgDn->setEnabled(true);
        }
    }

    if(pageNums == 0)
    {
        m_curPages = 0;
    }

    // 页信息
    QString str = tr("pageNum: ") + QString("%1/%2").arg(m_curPages).arg(pageNums);//页数:
    if(type == INTERFACE_SHORTCUT)
    {
        ui->labelShortCutPage->setText(str);
    }
    else if(type == INTERFACE_ACCESS)
    {
        ui->labelAssistPage->setText(str);
    }
}

//发送初始化字符串
void MainWidget::sendInitString(QString str)
{
    Qt::Alignment alignment = Qt::AlignHCenter|Qt::AlignBottom; // 设置一个格式
    emit(siSendLoadingMessage(str, alignment, Qt::red));
}

//刷新连接状态(1秒)
void MainWidget::refConnectUi(int alive)
{
    alive = 0;
    refConnectUi(g_pMachine, m_linkSta, alive);
}

//刷新连接状态
void MainWidget::refConnectUi(Machine *pMachine, int &linkSta, int alive)
{
    if(m_ifHMIDecrypt == 0)
    {
        return;
    }

    if(m_connectMode == USE_SERIAL_COMM)//串口连接方式
    {
        if(linkSta != pMachine->isConnected())
        {
            linkSta = pMachine->isConnected();
            if(linkSta == Connected)
            {
                if (pMachine != NULL)
                {
                    //连接后获取机器信息，用于获得剩余可用时间，小于5天主动提示用户
                    //此条语句需放在前面
                    pMachine->getInfoFromMachine();

                    pMachine->getSensorEnBmpFromMachine();//读取传感器信号
                    pMachine->getParasFromMachine();//获取参数
                    m_pMinTimer->start();//1分钟记录一次当前系统时间 ,连接成功以后开启计时器，记录时间 -rq
                    m_pMainWidgetFunction->setShutDownTime();//计算关机时间

                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()));
                    ui->labelState->setText(tr("Connected"));//状态：已连接
                }
            }
            else
            {
                ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Unconnected"));
                ui->labelState->setText(tr("Not connected"));//状态：未连接
            }
        }
    }
    else
    {
        if (pMachine != NULL)
        {
            if (linkSta != pMachine->isConnected() ||
                    pMachine->isConnected() == Connectting ||
                    alive == -1)
            {
                if (alive == -1)
                {
                    linkSta = 0;
                }
                else
                {
                    linkSta = pMachine->isConnected();//获取连接状态
                }

                if (linkSta == Connectting)//连接中...
                {
                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Connecting"));
                    ui->labelState->setText(tr("Connnecting..."));//状态：连接中...
                }
                else if (linkSta == Connected)//已连接
                {
                    //连接后获取机器信息，用于获得剩余可用时间，小于5天主动提示用户
                    //此条语句需放在前面
                    pMachine->getInfoFromMachine();

                    pMachine->getSensorEnBmpFromMachine();//读取传感器信号
                    pMachine->getParasFromMachine();//获取参数
                    m_pMinTimer->start();//1分钟记录一次当前系统时间 ,连接成功以后开启计时器，记录时间 -rq
                    m_pMainWidgetFunction->setShutDownTime();//计算关机时间

                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()));
                    ui->labelState->setText(tr("Connected"));//状态：已连接

                    /***
                界面启动时也会发送最后绣作的花样文件，
                连接成功后也会发送，但连接速度快，此时ds数据可能还没转换完成，
                所以连接成功后发送文件可能不成功，只是界面加载时会发送文件，
                因此二者不会重复发送文件；若断开连接再连接时此段代码会发送文件，
                界面加载部分不会发送；
                ***/
                    QByteArray ds16dat = g_pCurEmbData->getDsDat();//获得ds16数据
                    //如果当前所选文件路径不为空与ds16数据不为空时
                    if(m_curFilePath.length() > 0 && ds16dat.size() > 0)
                    {
                        //m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
                        //设置为按进度执行模式
                        //g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度
                    }
                }
                else//未连接
                {
                    ui->buttonConnect->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonConnect->objectName()+"Unconnected"));
                    ui->labelState->setText(tr("Not connected"));//状态：未连接
                }
            }
        }
    }
}

//隐藏菜单栏(frame)
void MainWidget::hideMenuFrame()
{
    ui->frameMenuBack->setVisible(false);
    ui->framePatternView->setVisible(false);
    ui->framePatternSet->setVisible(false);
    ui->frameParaSet->setVisible(false);
    ui->frameAccessFunction->setVisible(false);
    ui->frameShortcutFunction->setVisible(false);

    //设置按钮为非选中状态
    ui->buttonPatternSet->setChecked(false);
    ui->buttonPatternSet->setCheckable(false);
    ui->buttonAccessFunction->setChecked(false);
    ui->buttonAccessFunction->setCheckable(false);
    ui->buttonParaSet->setChecked(false);
    ui->buttonParaSet->setCheckable(false);
    ui->buttonShortcutFunction->setChecked(false);
    ui->buttonShortcutFunction->setCheckable(false);
    ui->buttonMainMenu->setChecked(false);
    ui->buttonMainMenu->setCheckable(false);
}

//根据文件格式不同显示不同花样参数
void MainWidget::showDiffPara(QString ext,s16 setFlag)
{
    if(setFlag == 0)
    {
        memset((char*)&m_patternSetPara,0,sizeof(PatternSetPara));
        //得到花样参数
        if(ext == "DST")
        {
            //绣花花样参数-花样设置参数
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN,PATTERNPARA_SORT_DSTR);

            DstHead *head = NULL;
            DataFileDst dst;
            dst.initFile(m_curFilePath);
            head = dst.getDstHead();
            if(head == NULL)
            {
                head = new DstHead();
                memset((char*)head,0,sizeof(DstHead));
            }
            dst.getBeginXYAndAnchorXY(head->startX,head->startY,head->anchorX,head->anchorY);

            m_patternSetPara.rotateStyle = head->rotateStyle;
            m_patternSetPara.rotateAngle = head->rotateAngle;
            m_patternSetPara.scanX = head->scanX;
            m_patternSetPara.scanY = head->scanY;
            m_patternSetPara.left = head->left;
            m_patternSetPara.front = head->front;
            m_patternSetPara.reinMode = head->reinMode;
            m_patternSetPara.reinNeedles = head->reinNeedles;
            m_patternSetPara.reinNum = head->reinNum;
            m_patternSetPara.normalStep = head->normalStep;
            m_patternSetPara.angleCorrOffset = head->angleCorrOffset;
            m_patternSetPara.angleCorrPosX = head->angleCorrPosX;
            m_patternSetPara.angleCorrPosY = head->angleCorrPosY;
            m_patternSetPara.angleCorrNegX = head->angleCorrNegX;
            m_patternSetPara.angleCorrNegY = head->angleCorrNegY;
            m_patternSetPara.startX = head->startX;
            m_patternSetPara.startY = head->startY;
            m_patternSetPara.anchorX = head->anchorX;
            m_patternSetPara.anchorY = head->anchorY;

            m_patternSetPara.cornerneedle = head->cornerneedle;
            m_patternSetPara.cutneedle = head->cutneedle;
        }
        else if(ext == "DSR")
        {
            //绣花花样参数-花样设置参数
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN,PATTERNPARA_SORT_DSTR);

            DsrHead *head = NULL;
            DataFileDsr dsr;
            dsr.initFile(m_curFilePath);
            head = dsr.getDsrHead();
            if(head == NULL)
            {
                head = new DsrHead();
                memset((char*)head,0,sizeof(DsrHead));
            }
            //dsr.getBeginXYAndAnchorXY(*(int*)&head->startX,*(int*)&head->startY,*(int*)&head->anchorX,*(int*)&head->anchorY);   //coco  屏蔽粗线布线机
            int tempStartX, tempStartY, tempAnchorX, tempAnchorY;

            // 将 float 的比特拷贝到 int
            memcpy(&tempStartX, &head->startX, sizeof(float));
            memcpy(&tempStartY, &head->startY, sizeof(float));
            memcpy(&tempAnchorX, &head->anchorX, sizeof(float));
            memcpy(&tempAnchorY, &head->anchorY, sizeof(float));

            // 调用函数，传递临时变量
            dsr.getBeginXYAndAnchorXY(tempStartX, tempStartY, tempAnchorX, tempAnchorY);

            m_patternSetPara.rotateStyle = head->rotateStyle;
            m_patternSetPara.rotateAngle = head->rotateAngle;
            m_patternSetPara.scanX = head->scanX;
            m_patternSetPara.scanY = head->scanY;
            m_patternSetPara.left = head->left;
            m_patternSetPara.front = head->front;
            m_patternSetPara.reinMode = head->reinMode;
            m_patternSetPara.reinNeedles = head->reinNeedles;
            m_patternSetPara.reinNum = head->reinNum;
            m_patternSetPara.normalStep = head->normalStep;
            m_patternSetPara.angleCorrOffset = head->angleCorrOffset;
            m_patternSetPara.angleCorrPosX = head->angleCorrPosX;
            m_patternSetPara.angleCorrPosY = head->angleCorrPosY;
            m_patternSetPara.angleCorrNegX = head->angleCorrNegX;
            m_patternSetPara.angleCorrNegY = head->angleCorrNegY;
            m_patternSetPara.startX = head->startX;
            m_patternSetPara.startY = head->startY;
            m_patternSetPara.anchorX = head->anchorX;
            m_patternSetPara.anchorY = head->anchorY;
            m_patternSetPara.bisect = head->bisect;

            m_patternSetPara.cornerneedle = head->cornerneedle;
            m_patternSetPara.cutneedle = head->cutneedle;
        }
        else if(ext == "QUI")
        {
            //绣花花样参数-花样设置参数
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN,PATTERNPARA_SORT_QUI);

            QuiFileHead *head = NULL;
            DataFileQui qui;
            qui.initFile(m_curFilePath);
            head = qui.getQuiHead();
            if(head == NULL)
            {
                head = new QuiFileHead();
                memset((char*)head,0,sizeof(QuiFileHead));
            }

            m_patternSetPara.rotateStyle = head->rotateStyle;
            m_patternSetPara.rotateAngle = head->rotateAngle;
            m_patternSetPara.normalStep = head->normalStep;
            m_patternSetPara.reinMode = head->reinMode;
            m_patternSetPara.reinNeedles = head->reinNeedles;
            m_patternSetPara.reinNum = head->reinNum;
            m_patternSetPara.angleCorrOffset = head->angleCorrOffset;
            m_patternSetPara.angleCorrPosX = head->angleCorrPosX;
            m_patternSetPara.angleCorrNegX = head->angleCorrNegX;
            m_patternSetPara.angleCorrPosY = head->angleCorrPosY;
            m_patternSetPara.angleCorrNegY = head->angleCorrNegY;
            m_patternSetPara.left = head->left;
            m_patternSetPara.front = head->front;
            m_patternSetPara.scanX = head->scanX;
            m_patternSetPara.scanY = head->scanY;

            m_patternSetPara.cornerneedle = head->cornerneedle;
            m_patternSetPara.cutneedle = head->cutneedle;
        }
        else if(ext == "QUIX")
        {
            //绣花花样参数-花样设置参数
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN,PATTERNPARA_SORT_QUI);

            QuixFileHead *head = NULL;
            DataFileQuix quix;
            quix.initFile(m_curFilePath);
            head = quix.getQuixHead();
            if(head == NULL)
            {
                head = new QuixFileHead();
                memset((char*)head,0,sizeof(QuixFileHead));
            }

            m_patternSetPara.rotateStyle = head->rotateStyle;
            m_patternSetPara.rotateAngle = head->rotateAngle;
            m_patternSetPara.normalStep = head->normalStep;
            m_patternSetPara.reinMode = head->reinMode;
            m_patternSetPara.reinNeedles = head->reinNeedles;
            m_patternSetPara.reinNum = head->reinNum;
            m_patternSetPara.angleCorrOffset = head->angleCorrOffset;
            m_patternSetPara.angleCorrPosX = head->angleCorrPosX;
            m_patternSetPara.angleCorrNegX = head->angleCorrNegX;
            m_patternSetPara.angleCorrPosY = head->angleCorrPosY;
            m_patternSetPara.angleCorrNegY = head->angleCorrNegY;
            m_patternSetPara.left = head->left;
            m_patternSetPara.front = head->front;
            m_patternSetPara.scanX = head->scanX;
            m_patternSetPara.scanY = head->scanY;

            m_patternSetPara.cornerneedle = head->cornerneedle;
            m_patternSetPara.cutneedle = head->cutneedle;
        }
        else if(ext == "PLT")
        {
            //平板切割算法参数设置
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN,PATTERNPARA_SORT_PLT);
        }

        else if(ext == "PREVIEW")
        {
            m_pParameterSetDlg->setItemList(operate,PARA_TYPE_PATTERN,PATTERN_PREVIEW);
        }

        m_pParameterSetDlg->setItemValue(SET_ROTATESTYLE, m_patternSetPara.rotateStyle);     //旋转式样
        m_pParameterSetDlg->setItemValue(SET_ROTATEANGLE, m_patternSetPara.rotateAngle);     //旋转角度
        m_pParameterSetDlg->setItemValue(SET_SETSTEPSIZE, m_patternSetPara.normalStep);     //针步大小
        m_pParameterSetDlg->setItemValue(SET_REINMODE, m_patternSetPara.reinMode);     //加固方式
        m_pParameterSetDlg->setItemValue(SET_REINNEEDLE, m_patternSetPara.reinNeedles);     //加固针数
        m_pParameterSetDlg->setItemValue(SET_REINNUM, m_patternSetPara.reinNum);     //加固次数
        m_pParameterSetDlg->setItemValue(SET_ANGLECORROFFSET, m_patternSetPara.angleCorrOffset);     //角度修正量
        m_pParameterSetDlg->setItemValue(SET_ANGLECORRPOSX, m_patternSetPara.angleCorrPosX);     //角度修正量X正
        m_pParameterSetDlg->setItemValue(SET_ANGLECORRNEGX, m_patternSetPara.angleCorrNegX);     //角度修正量X负
        m_pParameterSetDlg->setItemValue(SET_ANGLECORRPOSY, m_patternSetPara.angleCorrPosY);     //角度修正量Y正
        m_pParameterSetDlg->setItemValue(SET_ANGLECORRNEGY, m_patternSetPara.angleCorrNegY);     //角度修正量Y负
        m_pParameterSetDlg->setItemValue(SET_SETLEFT, m_patternSetPara.left);                    //左边
        m_pParameterSetDlg->setItemValue(SET_SETFRONT, m_patternSetPara.front);             //前边
        m_pParameterSetDlg->setItemValue(SET_SCANX, m_patternSetPara.scanX);                  //缩放x
        m_pParameterSetDlg->setItemValue(SET_SCANY, m_patternSetPara.scanY);                  //缩放y
        m_pParameterSetDlg->setItemValue(SET_ANCHORX, m_patternSetPara.anchorX);        //定位点X
        m_pParameterSetDlg->setItemValue(SET_ANCHORY, m_patternSetPara.anchorY);         //定位点Y
        m_pParameterSetDlg->setItemValue(SET_STARTX, m_patternSetPara.startX);                 //起始点X
        m_pParameterSetDlg->setItemValue(SET_STARTY, m_patternSetPara.startY);                 //起始点Y
        m_pParameterSetDlg->setItemValue(SET_BISECT, m_patternSetPara.bisect);                 //平分参数

        m_pParameterSetDlg->setItemValue(SET_CORNERNEEDLE, m_patternSetPara.cornerneedle);//拐角增加针步
        m_pParameterSetDlg->setItemValue(SET_CUTNEEDLE, m_patternSetPara.cutneedle);//拐角分割针步
    }
    else if(setFlag != 0)
    {
        //文件头花样参数
        m_patternSetPara.rotateStyle = m_pParameterSetDlg->getItemValue(SET_ROTATESTYLE);    //旋转式样
        m_patternSetPara.rotateAngle = m_pParameterSetDlg->getItemValue(SET_ROTATEANGLE);    //旋转角度
        m_patternSetPara.normalStep = m_pParameterSetDlg->getItemValue(SET_SETSTEPSIZE);  //针步大小
        m_patternSetPara.reinMode = m_pParameterSetDlg->getItemValue(SET_REINMODE);     //加固方式
        m_patternSetPara.reinNeedles = m_pParameterSetDlg->getItemValue(SET_REINNEEDLE);     //加固针数
        m_patternSetPara.reinNum = m_pParameterSetDlg->getItemValue(SET_REINNUM);     //加固次数
        m_patternSetPara.angleCorrOffset = m_pParameterSetDlg->getItemValue(SET_ANGLECORROFFSET);  //角度修正量
        m_patternSetPara.angleCorrPosX = m_pParameterSetDlg->getItemValue(SET_ANGLECORRPOSX);  //角度修正x正
        m_patternSetPara.angleCorrNegX = m_pParameterSetDlg->getItemValue(SET_ANGLECORRNEGX);  //角度修正x负
        m_patternSetPara.angleCorrPosY = m_pParameterSetDlg->getItemValue(SET_ANGLECORRPOSY);  //角度修正y正
        m_patternSetPara.angleCorrNegY = m_pParameterSetDlg->getItemValue(SET_ANGLECORRNEGY);  //角度修正y负
        m_patternSetPara.left = m_pParameterSetDlg->getItemValue(SET_SETLEFT);  //左边
        m_patternSetPara.front = m_pParameterSetDlg->getItemValue(SET_SETFRONT);    //前边
        m_patternSetPara.scanX = m_pParameterSetDlg->getItemValue(SET_SCANX);   //缩放x
        m_patternSetPara.scanY = m_pParameterSetDlg->getItemValue(SET_SCANY);   //缩放y
        m_patternSetPara.anchorX = m_pParameterSetDlg->getItemValue(SET_ANCHORX);  //定位点X
        m_patternSetPara.anchorY = m_pParameterSetDlg->getItemValue(SET_ANCHORY);    //定位点Y
        m_patternSetPara.startX = m_pParameterSetDlg->getItemValue(SET_STARTX);   //起始点X
        m_patternSetPara.startY = m_pParameterSetDlg->getItemValue(SET_STARTY);   //起始点Y
        m_patternSetPara.bisect = m_pParameterSetDlg->getItemValue(SET_BISECT);   //平分参数

        m_patternSetPara.cornerneedle = m_pParameterSetDlg->getItemValue(SET_CORNERNEEDLE);//拐角增加针步
        m_patternSetPara.cutneedle = m_pParameterSetDlg->getItemValue(SET_CUTNEEDLE);//拐角分割针步
    }
}

//计算起始点和定位点并设置
void MainWidget::calPointsAndSet(s16 type)
{
    //计算起始点和定位点，并把定位点和起始点更新到ds16数据中
    //花版的定位点为绝对坐标数据点，起始点为相对于定位点的相对坐标点，第一针为相对于起始点的坐标点
    //有的花版起始点有偏移量，第一针偏移量为0，有的花版起始点偏移量为0，第一针有偏移量
    //所以ds16文件头定位点坐标就是花版中的定位点，起始点坐标为花版中的定位点坐标+起始点坐标+第一针的坐标，同时ds16数据的第一针坐标偏移应置为0

    //单针绗缝机根据向前、向后重新计算起始点
    if(g_emMacType == MACHINE_HIGHSPEEDSINGLEQUI)
    {
        int left = m_patternSetPara.left;
        int front = m_patternSetPara.front;
        int minX = g_pCurEmbData->getMinX();
        int minY = g_pCurEmbData->getMinY();
        int oldBeginX = g_pCurEmbData->getBeginX();
        int oldBeginY = g_pCurEmbData->getBeginY();
        int newBeginX = oldBeginX - minX + left;
        int newBeginY = oldBeginY - minY + front;

        m_pMainWidgetFunction->funSetStartPoint(m_curFilePath,newBeginX,newBeginY, 0, false,false);
    }
    //五头机、服装机需要设置定位点和起始点（先设置定位点，起始点计算需要用到定位点）
    if(g_emMacType == MACHINE_FIVEHEADPRECISIONSEWING ||
            g_emMacType == MACHINE_CLOTHINGMAC  || g_emMacType == MACHINE_THICK_WIRING)
    {
        m_pMainWidgetFunction->funSetAnchorPoint(m_curFilePath,m_patternSetPara.anchorX,m_patternSetPara.anchorY, 0, false,false);
        m_pMainWidgetFunction->funSetStartPoint(m_curFilePath,m_patternSetPara.startX,m_patternSetPara.startY, 0, false,false);
    }

    //平板切割机回工作点时需要把工作点坐标设置为定位点
    if(g_emMacType == MACHINE_FLATCUTTINGMAC || g_emMacType == MACHINE_FLYFLATCUTTING)
    {
        int x = 0;
        int y = 0;

        if(type == 0)//工作点
        {
            //            x = g_pMachine->getMcPara().buf[41];//X+
            //            y = g_pMachine->getMcPara().buf[43];//Y+
            x = g_pSettings->readFromIniFile("FlatPanel/WorkPointX").toInt();
            y = g_pSettings->readFromIniFile("FlatPanel/WorkPointY").toInt();
            //            x = 165000;//X+
            //            y = 88000;//Y+

            //=============== coco 20241125飞行平板切割机临时加===================
            x = g_pSettings->readFromIniFile("FlatPanel/AnchorPointX").toInt();
            y = g_pSettings->readFromIniFile("FlatPanel/AnchorPointY").toInt();
            //=============== coco 20241125飞行平板切割机临时加===================

        }
        else//切割点
        {
            //读取配置文件上次切割点位置坐标
            x = g_pSettings->readFromIniFile("FlatPanel/AnchorPointX").toInt();
            y = g_pSettings->readFromIniFile("FlatPanel/AnchorPointY").toInt();
        }
        m_pMainWidgetFunction->funSetAnchorPointForFlat(m_curFilePath,x,y,-1);
        int begX = g_pCurEmbData->getBeginX();
        int begY = g_pCurEmbData->getBeginY();
        m_patternSetPara.startX = begX;
        m_patternSetPara.startY = begY;
    }
}

s16 MainWidget::appendDiffAbsData(QString ext)
{
    //添加一个花样文件
    if(ext == "DST")//dst文件
    {
        DataFileDst dst;
        dst.initFile(m_curFilePath);
        dst.convertDataToAbs();

        //将花样参数配置写回到源文件中
        DstHead *head = dst.getDstHead();
        if(head == NULL){return -1;}

        head->rotateStyle = m_patternSetPara.rotateStyle;
        head->rotateAngle = m_patternSetPara.rotateAngle;
        head->scanX = m_patternSetPara.scanX;
        head->scanY =  m_patternSetPara.scanY;
        head->left = m_patternSetPara.left;
        head->front =  m_patternSetPara.front;
        head->reinMode = m_patternSetPara.reinMode;
        head->reinNeedles = m_patternSetPara.reinNeedles;
        head->reinNum = m_patternSetPara.reinNum;
        head->normalStep = m_patternSetPara.normalStep;
        head->angleCorrOffset = m_patternSetPara.angleCorrOffset;
        head->angleCorrPosX = m_patternSetPara.angleCorrPosX;
        head->angleCorrPosY = m_patternSetPara.angleCorrPosY;
        head->angleCorrNegX = m_patternSetPara.angleCorrNegX;
        head->angleCorrNegY = m_patternSetPara.angleCorrNegY;

        head->cornerneedle = m_patternSetPara.cornerneedle;//多针旋梭-拐角添加针步标志
        head->cutneedle = m_patternSetPara.cutneedle;//多针旋梭-拐角分割针步标志

        dst.writePatternParaToFile(head);
        g_pCurEmbData->setAbsDat(dst.getEmbAbsData());

        g_pCurEmbData->m_addcorner = head->cornerneedle;
        g_pCurEmbData->m_cutcorner = head->cutneedle;
        g_pCurEmbData->m_cornerPX = head->angleCorrPosX*10;
        g_pCurEmbData->m_cornerNX = head->angleCorrNegX*10;
        g_pCurEmbData->m_cornerPY = head->angleCorrPosY*10;
        g_pCurEmbData->m_cornerNY = head->angleCorrNegY*10;

        m_patternSetPara.scanX = head->scanX*10;
        m_patternSetPara.scanY = head->scanY*10;
        m_patternSetPara.normalStep *= 10;
    }
    else if(ext == "DSR")//dsr文件
    {
        DataFileDsr dsr;
        dsr.initFile(m_curFilePath);
        dsr.convertDataToEmbAbs();//转换为绝对数据（中间数据）

        //将花样参数配置写回到源文件中
        DsrHead *head = dsr.getDsrHead();
        if(head == NULL){return -1;}

        head->rotateStyle = m_patternSetPara.rotateStyle;
        head->rotateAngle = m_patternSetPara.rotateAngle;
        head->scanX = m_patternSetPara.scanX;
        head->scanY =  m_patternSetPara.scanY;
        head->left = m_patternSetPara.left;
        head->front =  m_patternSetPara.front;
        head->reinMode = m_patternSetPara.reinMode;
        head->reinNeedles = m_patternSetPara.reinNeedles;
        head->reinNum = m_patternSetPara.reinNum;
        head->normalStep = m_patternSetPara.normalStep;
        head->angleCorrOffset = m_patternSetPara.angleCorrOffset;
        head->angleCorrPosX = m_patternSetPara.angleCorrPosX;
        head->angleCorrPosY = m_patternSetPara.angleCorrPosY;
        head->angleCorrNegX = m_patternSetPara.angleCorrNegX;
        head->angleCorrNegY = m_patternSetPara.angleCorrNegY;
        head->bisect = m_patternSetPara.bisect;
        qDebug()<<"pattern:"<<m_patternSetPara.bisect;

        head->cornerneedle = m_patternSetPara.cornerneedle ;
        head->cutneedle = m_patternSetPara.cutneedle ;
        //        head->startX = m_patternSetPara.startX;
        //        head->startY = m_patternSetPara.startY;
        //        head->anchorX = m_patternSetPara.anchorX;
        //        head->anchorY = m_patternSetPara.anchorY;

        dsr.writePatternParaToFile(head);

        g_pCurEmbData->m_addcorner = head->cornerneedle;
        g_pCurEmbData->m_cutcorner = head->cutneedle;
        g_pCurEmbData->m_cornerPX = head->angleCorrPosX*10;
        g_pCurEmbData->m_cornerNX = head->angleCorrNegX*10;
        g_pCurEmbData->m_cornerPY = head->angleCorrPosY*10;
        g_pCurEmbData->m_cornerNY = head->angleCorrNegY*10;

        m_patternSetPara.scanX = head->scanX*10;
        m_patternSetPara.scanY = head->scanY*10;
        m_patternSetPara.normalStep *= 10;
        g_pCurEmbData->setAbsDat(dsr.getEmbAbsData());  //得到转换后的绝对坐标数据
    }
    else if(ext == "QUI")
    {
        DataFileQui qui;
        qui.initFile(m_curFilePath);

        //将花样参数配置写回到源文件中，需放在转换中间数据之前，因为中间数据需要根据文件头参数进行数据变换
        QuiFileHead *head = qui.getQuiHead();
        if(head == NULL){return -1;}

        head->rotateStyle = m_patternSetPara.rotateStyle;
        head->rotateAngle = m_patternSetPara.rotateAngle;
        head->normalStep = m_patternSetPara.normalStep;
        head->reinMode = m_patternSetPara.reinMode;
        head->reinNeedles = m_patternSetPara.reinNeedles;
        head->reinNum = m_patternSetPara.reinNum;
        head->angleCorrOffset = m_patternSetPara.angleCorrOffset;
        head->angleCorrPosX = m_patternSetPara.angleCorrPosX;
        head->angleCorrPosY = m_patternSetPara.angleCorrPosY;
        head->angleCorrNegX = m_patternSetPara.angleCorrNegX;
        head->angleCorrNegY = m_patternSetPara.angleCorrNegY;
        head->left = m_patternSetPara.left;
        head->front = m_patternSetPara.front;
        head->scanX = m_patternSetPara.scanX;
        head->scanY = m_patternSetPara.scanY;

        head->cornerneedle = m_patternSetPara.cornerneedle ;
        head->cutneedle = m_patternSetPara.cutneedle ;

        qui.writePatternParaToFile(head);

        qui.convertDataToEmbAbs();//转换为绝对数据（中间数据）
        g_pCurEmbData->setAbsDat(qui.getEmbAbsData());//得到转换后的绝对坐标数据

        g_pCurEmbData->m_addcorner = head->cornerneedle;
        g_pCurEmbData->m_cutcorner = head->cutneedle;
        g_pCurEmbData->m_cornerPX = head->angleCorrPosX*10;
        g_pCurEmbData->m_cornerNX = head->angleCorrNegX*10;
        g_pCurEmbData->m_cornerPY = head->angleCorrPosY*10;
        g_pCurEmbData->m_cornerNY = head->angleCorrNegY*10;

        m_patternSetPara.scanX = 0;
        m_patternSetPara.scanY = 0;
        m_patternSetPara.normalStep = 0;
    }
    else if(ext == "QUIX")
    {
        DataFileQuix quix;
        quix.initFile(m_curFilePath);

        //将花样参数配置写回到源文件中，需放在转换中间数据之前，因为中间数据需要根据文件头参数进行数据变换
        QuixFileHead *head = quix.getQuixHead();
        if(head == NULL){return -1;}

        head->rotateStyle = m_patternSetPara.rotateStyle;
        head->rotateAngle = m_patternSetPara.rotateAngle;
        head->normalStep = m_patternSetPara.normalStep;
        head->reinMode = m_patternSetPara.reinMode;
        head->reinNeedles = m_patternSetPara.reinNeedles;
        head->reinNum = m_patternSetPara.reinNum;
        head->angleCorrOffset = m_patternSetPara.angleCorrOffset;
        head->angleCorrPosX = m_patternSetPara.angleCorrPosX;
        head->angleCorrPosY = m_patternSetPara.angleCorrPosY;
        head->angleCorrNegX = m_patternSetPara.angleCorrNegX;
        head->angleCorrNegY = m_patternSetPara.angleCorrNegY;
        head->left = m_patternSetPara.left;
        head->front = m_patternSetPara.front;
        head->scanX = m_patternSetPara.scanX;
        head->scanY = m_patternSetPara.scanY;

        head->cornerneedle = m_patternSetPara.cornerneedle ;
        head->cutneedle = m_patternSetPara.cutneedle ;

        quix.writePatternParaToFile(head);

        quix.convertDataToEmbAbs();//转换为绝对数据（中间数据）
        g_pCurEmbData->setAbsDat(quix.getEmbAbsData());//得到转换后的绝对坐标数据

        g_pCurEmbData->m_addcorner = head->cornerneedle;
        g_pCurEmbData->m_cutcorner = head->cutneedle;
        g_pCurEmbData->m_cornerPX = head->angleCorrPosX*10;
        g_pCurEmbData->m_cornerNX = head->angleCorrNegX*10;
        g_pCurEmbData->m_cornerPY = head->angleCorrPosY*10;
        g_pCurEmbData->m_cornerNY = head->angleCorrNegY*10;

        m_patternSetPara.scanX = 0;
        m_patternSetPara.scanY = 0;
        m_patternSetPara.normalStep = 0;
    }
    else if(ext == "PLT")
    {
        ImportHPGL importHPGL;

        if (importHPGL.IsSecretFile(m_curFilePath) == true)
        {
            // 文件路径
            QDir apppath(qApp->applicationDirPath());
            QString strSecretFile = apppath.path() + apppath.separator() + "Secret.plt";

            importHPGL.BitMapDtat(m_curFilePath,strSecretFile);
            importHPGL.IniPara();
            importHPGL.ReadSecretFile(strSecretFile);
        }
        else
        {
            importHPGL.IniPara();
            importHPGL.Read(m_curFilePath);
        }
        importHPGL.convertDataToEmbAbs();// 转换为绝对数据（中间数据）
        QByteArray ary = importHPGL.getEmbAbsData();
        g_pCurEmbData->setAbsDat(ary);//得到转换后的绝对坐标数据
    }
    else if(ext == "DXF")
    {
        /*
        DXF_CreationClass dxf;
        dxf.IniPara();
        dxf.Read(m_curFilePath);
        dxf.convertDataToEmbAbs();// 转换为绝对数据（中间数据）
        QByteArray ary = dxf.getEmbAbsData();
        g_pCurEmbData->setAbsDat(ary);//得到转换后的绝对坐标数据
        */
    }
    else
    {
        return -1;
    }
    return 0;
}

//重置所有数据
void MainWidget::resetAllData()
{
    m_forwardBackNeedleIdx = 0;
    ui->frameForwardBack->setVisible(false);

    g_pCurEmbData->getDsDat();

    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        //由于飞梭机与多针旋梭机显示存在一定差异，故而还需完善一个新的显示方法
        //罗拉补偿-预留位（当前直接使用绘制数据）
        QByteArray ary = g_pCurEmbData->getDsDat();
        if(ary.size() <= 0)
        {
            return;
        }

        unsigned char arrayNeedle1[LAYOUTNEEDLENUM];  // 第1排排针
        unsigned char arrayNeedle2[LAYOUTNEEDLENUM];  // 第2排排针
        unsigned int leftRightNeedleSpace = 12700;// 左右针间距 6350

        bool spindletype = g_pSettings->readFromIniFile("PatternPreView/SpindleType").toInt();
        unsigned int needleLayoutSpace12 = g_pSettings->readFromIniFile("PatternPreView/NeedleRowsSpacing").toInt();   // 第1、2排针间距
        unsigned int needlesSpace = g_pSettings->readFromIniFile("PatternPreView/NeedleSpacing").toInt();  // 针与针之间间距
        bool lowrHeadCenter = g_pSettings->readFromIniFile("PatternPreView/HeadCentered").toInt();  // 下排机头居中

        //前排循环
        for(u16 i = 0; i < sizeof(arrayNeedle1); i++)
        {
            arrayNeedle1[i] = NEEDLELEFT;
        }

        //中排循环
        for(u16 i = 0; i < sizeof(arrayNeedle2); i++)
        {
            if(!spindletype)
                break;

            if(lowrHeadCenter)
            {
                arrayNeedle2[i] = NEEDLERIGHT;
            }else
            {
                arrayNeedle2[i] = NEEDLELEFT;
            }
        }

        if(m_curFilePath.length() <= 0)
        {
            return;
        }

        g_pCurEmbData->getOneDispDat(ary);
        if(!spindletype)
        {
            g_pCurEmbData->resetLayoutDispDat(arrayNeedle1,NULL,NULL,leftRightNeedleSpace,needlesSpace,needleLayoutSpace12,0,0);
        }
        else
        {
            g_pCurEmbData->resetLayoutDispDat(arrayNeedle1,arrayNeedle2,NULL,leftRightNeedleSpace,needlesSpace,needleLayoutSpace12,0,0);
        }
        g_pCurEmbData->createDispFromEmbDs16DatForFlyShuttle(1);
    }
    else
    {
        g_pCurEmbData->setEmbData(g_emMacType);// ds16数据转换为画图数据
    }

    //加载图片的进度条显示
    ui->progressBar->setVisible(true);
    int value = g_pCurEmbData->getStitchNums() / TENTHOUSANDNEEDLE;
    ui->progressBar->setRange(1,value);
    ui->progressBar->setValue(1);

    m_dispMode = EmbData::DISP_ALL_EXEC;
    g_pCurEmbData->setDispMode(m_dispMode, 1);    // 重新画图
    m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
    g_pCurEmbData->setDispMode(m_dispMode, 0);    // 设置为按进度执行模式

    m_curDatIdx = 0;

    ui->framePatternView->setVisible(true);
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);

    ui->lab_Index_2->setText("0/0");
    ui->lab_StartPoint_2->setText("0/0");
    ui->lab_Locate_2->setText("0/0");
    ui->lab_Range_2->setText("0/0");
    ui->lab_Position_2->setText("0/0");
    ui->lab_Production_2->setText("0");
    ui->lab_Schedule_2->setText("0%");

    ui->progressBar->setVisible(false);

    if(g_emMacType == MACHINE_DRAWING)
    {
        ui->lab_Locate_2->setText("0");
    }
}

//花样选择
void MainWidget::patternSelect()
{
    //获得花样选择的图标字符
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNSELECT)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

            break;
        }
    }

    m_pPatternSelectWi->setTypeLogo(tStyle);
    m_pPatternSelectWi->setMainTitle(tr("Pattern selection"));
    m_pPatternSelectWi->setSubTitle(tr("Pattern setting > Pattern selection"));

    m_pPatternSelectWi->createCurDirPatterns();
    m_pPatternSelectWi->show();

    //    showPatternPreview();
}

//显示机器运行状态中的信息
void MainWidget::showExecInfo()
{
    // 速度
    if (m_curRpm != (int)m_mcStatus.runSpeed)        // 运行速度
    {
        m_curRpm = (int)m_mcStatus.runSpeed;
        QString str;
        str.sprintf("%d", m_curRpm);
        showWorkSpeed(str);
    }

    // 文件执行进度(当前针数) labelNeedleIdx
    if (m_curDatIdx != (int)m_mcStatus.dataIdx)
    {
        m_curDatIdx = (int)m_mcStatus.dataIdx;
        reSetDatIdx(m_curDatIdx);
        QPixmap patternPix = g_pCurEmbData->getPreviewImage();
        ui->labelPatternView->setPixmap(patternPix);
    }

    //针数索引
    int totalStitchNum = g_pCurEmbData->getStitchNums();
    ui->lab_Index_2->setText(QString("%1/%2")
                             .arg(QString::number(m_mcStatus.dataIdx))//当前索引
                             .arg(QString::number(totalStitchNum)));//总针步

    if(totalStitchNum > 0){ //避免除零错误
        QString schedule = QString("%1%").arg(QString::number((m_mcStatus.dataIdx*100)/totalStitchNum));
        ui->lab_Schedule_2->setText(schedule);
    }

    //产量
    //250407 多针旋梭机修改为 产量/产量预设
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        int val = g_pMachine->getWkPara().buf[33];
        ui->lab_Production_2->setText(QString::number(m_mcStatus.outCounter/1000.0, 'f' , 1 )+"/"+QString::number(val/ 1000.0 , 'f' , 1 ) + " m");
    }else
    {
        ui->lab_Production_2->setText(QString::number(m_mcStatus.outCounter));
    }

    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        //多针旋梭机 需要显示底线长度 单独加入两个label修改较多，故而使用位置label直接替换
        ui->lab_Position_2->setText(QString::number(m_mcStatus.btrdLength/100000.0 , 'f' , 1 ) + " m");
    }
    else
    {
        // 当前xy绝对坐标
        double xPos = m_mcStatus.xPos*0.01;
        double yPos = m_mcStatus.yPos*0.01;

        if(g_emMacType == MACHINE_FLATCUTTINGMAC)//平板切割机
        {
            //设置控制动作后的反馈数据
            m_pControlActionWi->setdefName(3,m_mcStatus.motosPos3);
            m_pControlActionWi->setdefName(4,m_mcStatus.motosPos4);
        }

        QString xyStr = QString("%1/%2").arg(QString::number(xPos,'f',2)).arg(QString::number(yPos,'f',2));
        ui->lab_Position_2->setText(xyStr);
    }

}

void MainWidget::showPatternPreview()
{
    hideMenuFrame();
    QFile curfile(m_curFilePath);
    if(m_curFilePath.length() <= 0 ||
            (!curfile.exists()))//未选择文件时不显示颜色和花样信息
    {
        ui->framePatternView->setVisible(false);
    }
    else
    {
        ui->framePatternView->setVisible(true);
        ui->labelPatternView->setVisible(true);//非预览模式绘制区域
    }

    //主界面按钮选中
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

//设置UI界面按钮的使能
void MainWidget::setUiBtnEnable(bool bValue)
{
    ui->frameMainFunction->setEnabled(bValue);
    ui->buttonNineBtn1->setEnabled(bValue);
    ui->buttonNineBtn2->setEnabled(bValue);
    ui->buttonNineBtn3->setEnabled(bValue);
    ui->buttonNineBtn4->setEnabled(bValue);
    ui->buttonNineBtnUp->setEnabled(bValue);
    ui->buttonNineBtnDown->setEnabled(bValue);
    ui->buttonNineBtnLeft->setEnabled(bValue);
    ui->buttonNineBtnRight->setEnabled(bValue);
    ui->buttonNineBtnMiddle->setEnabled(bValue);
}

void MainWidget::showSpeedFrame()
{
    ui->frameNineBtn->hide();
    ui->buttonNineBtn1->hide();
    ui->buttonNineBtnUp->hide();
    ui->buttonNineBtn2->hide();
    ui->buttonNineBtnLeft->hide();
    ui->buttonNineBtnMiddle->hide();
    ui->buttonNineBtnRight->hide();
    ui->buttonNineBtn3->hide();
    ui->buttonNineBtnDown->hide();
    ui->buttonNineBtn4->hide();
    //显示调速表和调速按钮
    ui->frameSpeed->show();

    ui->labelSpeed->show();//显示机器运行速度的数字的数码管
    ui->labelSpeed1->show();
    ui->labelSpeed2->show();
    ui->labelSpeed3->show();
    ui->labelSpeed4->show();
    if(g_emMacType != MACHINE_FLYFLATCUTTING){ //飞行切割不显示
        ui->buttonSpeedDec->show();
        ui->buttonStartStop->show();
        ui->buttonSpeedAdd->show();
    }
}

void MainWidget::showNineFrame()
{
    //进入到待机状态，隐藏调速表，显示方向键
    if(g_emMacType != MACHINE_MULTINEEDLEROTARY)
        ui->buttonNineBtn4->setTopImage(m_setControlStyle.getTopStyleSheet(ui->buttonNineBtn4->objectName()));

    ui->frameSpeed->hide();
    ui->buttonSpeedDec->hide();
    ui->buttonSpeedAdd->hide();
    ui->labelSpeed->hide();
    ui->labelSpeed1->hide();
    ui->labelSpeed2->hide();
    ui->labelSpeed3->hide();
    ui->labelSpeed4->hide();
    //显示调速表和调速按钮
    ui->frameNineBtn->show();
    ui->buttonNineBtn1->show();
    ui->buttonNineBtn2->show();
    ui->buttonNineBtn3->show();
    ui->buttonNineBtn4->show();
    ui->buttonNineBtnDown->show();
    ui->buttonNineBtnLeft->show();
    ui->buttonNineBtnMiddle->show();
    ui->buttonNineBtnRight->show();
    ui->buttonNineBtnUp->show();
}

void MainWidget::setNotExecing()
{
    if(m_dispMode != EmbData::DISP_EXECING)//不是执行状态，重置
    {
        g_pCurEmbData->setViewInfo(m_embBackPix);//带背景图的背景
        g_pCurEmbData->setDrawMode(EmbData::DRAW_VIEW);//非预览模式
        g_pCurEmbData->setEmbData(g_emMacType);//ds16数据转换为画图数据

        m_dispMode = EmbData::DISP_ALL_EXEC;
        g_pCurEmbData->setDispMode(m_dispMode, 1);    // 重新画图

        m_dispMode = EmbData::DISP_EXECING;           // 设置为执行模式
        g_pCurEmbData->setDispMode(m_dispMode, 0);       // 设置为按进度执行模式
        g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度

        QPixmap patternPix = g_pCurEmbData->getPreviewImage();
        ui->labelPatternView->setPixmap(patternPix);
    }
}

void MainWidget::reSetDatIdx(int newidx)
{
    int totalStitchNum = g_pCurEmbData->getStitchNums();

    if (newidx <= 0)
    {
        m_curDatIdx = 0;         // 当前执行进度
    }
    else if (newidx >= totalStitchNum)
    {
        m_curDatIdx = m_curDatIdx - 1;         // 当前执行进度
    }

    // 文件idx信息
    QString str;
    str.sprintf("%d", m_curDatIdx);
    QString indexStr = ui->lab_Index_2->text();
    QString newindexStr = QString("%1/%2").arg(m_curDatIdx).arg(indexStr.right(indexStr.size() - indexStr.indexOf('/') - 1));
    ui->lab_Index_2->setText(newindexStr);

    // 更新进度显示
    g_pCurEmbData->setExecIndex(m_curDatIdx);
}

//前进回退
void MainWidget::funForwardOrBack()
{

    //显示主界面
    hideMenuFrame();
    setUiBtnEnable(false);
    showPatternPreview();
    m_forwardBackNeedleIdx = m_curDatIdx;

    g_pCurEmbData->setExecIndex(m_forwardBackNeedleIdx);// 更新进度显示

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);

    int totalStitchNum = g_pCurEmbData->getStitchNums();
    QString strNeedle;
    strNeedle.sprintf("%d / %d",m_forwardBackNeedleIdx,totalStitchNum);
    ui->labelNeedleCurAndTotal->setText(strNeedle);

    ui->frameForwardBack->setVisible(true);
    ui->frameForwardBack->raise();
}

void MainWidget::addOrDecNeedleIdx(int &idx)
{
    if( g_pMachine == NULL || 0 )
    {
        return;
    }

    if(idx < 0)
    {
        idx = 0;
    }

    int totalStitchNum = g_pCurEmbData->getStitchNums();//总针数
    if(idx > totalStitchNum)
    {
        idx = totalStitchNum;
    }

    memset(&m_expara,0,sizeof(FileExecPara));

    int posx, posy, cidx;
    g_pCurEmbData->getPosInfoFromNeedleIdx(idx, posx, posy, cidx);

    m_expara.newIdx = idx;
    m_expara.newXPos = posx;
    m_expara.newYPos = posy;
    m_expara.newRPos = 0;

    QString strNeedle;
    strNeedle.sprintf("%d / %d",idx,totalStitchNum);
    ui->labelNeedleCurAndTotal->setText(strNeedle);

    //画执行进度图
    g_pCurEmbData->setExecIndex(idx);// 更新针数

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);
}

//获取常用按钮样式
QString MainWidget::getCommonBtnStyle(int idx)
{
    QString styleStr;
    //检测快捷按钮条目
    for(int i = 0; i < m_quickItemList.size(); i++)//快捷功能中的快捷条目列表
    {
        int enumFun = m_quickItemList[i].m_enumFunction;
        if(idx == enumFun)//功能索引等于快捷按钮功能索引
        {
            //获取顶层图标样式表
            styleStr = m_quickItemList[i].m_topImageName;
            break;
        }
    }

    if(idx == FUN_PATTERNSELECT)//功能索引等于花样选择
    {
        //获得花样选择的图标字符
        for(int i = 0; i < m_patternSetItemList.size(); i++)
        {
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNSELECT)
            {
                styleStr = m_patternSetItemList[i].m_topImageName;
                break;
            }
        }
    }

    return styleStr;
}

void MainWidget::runCommonBtnFunction(int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }
    switch (idx)
    {
    case FUN_ALLTOZERO://全部归零
        m_pMainWidgetFunction->funAllToZero();
        break;
    case FUN_SPINDLEJOG://主轴点动（平绣，毛巾）
        m_pMainWidgetFunction->funSpindleJog();
        break;
    case FUN_SPINDLEROTATE://主轴旋转
        m_pMainWidgetFunction->funSpindleRotate();
        break;
    case FUN_CUTTINGPOINT:
        m_pMainWidgetFunction->funBackToCuttringPoint();
        m_backPosFlag = 1;
        break;
    case FUN_BACKWORKPOINT://回工作点
        m_pMainWidgetFunction->funBackWorkPoint();
        break;
    case FUN_BACKTOORIGIN://回原点
        m_pMainWidgetFunction->funBackToOrigin();
        m_backPosFlag = 0;
        break;
    case FUN_SETOFFSETPOINT://定偏移点
        m_pMainWidgetFunction->funSetOffsetPoint();
        break;
    case FUN_BACKOFFSETPOINT://回偏移点
        m_pMainWidgetFunction->funBackOffsetPoint();
        break;
    case FUN_SETSTARTPOINT://定起始点
        if(g_emMacType == MACHINE_FIVEHEADPRECISIONSEWING)   // 五头精密缝
        {
            if(g_emUser != repair)//权限不够先登录     coco 20241212应美国客户需求加了密码
            {
                m_pMainWidgetFunction->slotUserLogin(repair);
                if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                    return;
            }

            if(m_pMainWidgetFunction != NULL)
            {
                m_pMainWidgetFunction->funSetStartPoint(m_curFilePath,m_mcStatus.xPos,m_mcStatus.yPos,1);
                ui->lab_StartPoint_2->setText(QString("%1/%2").arg(QString::number(m_mcStatus.xPos*0.01,'f',2)).arg(QString::number(m_mcStatus.yPos*0.01,'f',2)));
            }
        }
        else
        {
            m_pMainWidgetFunction->funSetStartPoint(m_curFilePath,m_mcStatus.xPos,m_mcStatus.yPos,1);
            ui->lab_StartPoint_2->setText(QString("%1/%2").arg(QString::number(m_mcStatus.xPos*0.01,'f',2)).arg(QString::number(m_mcStatus.yPos*0.01,'f',2)));
        }
        break;
    case FUN_BACKSTARTPOINT:// 回起针点
        m_pMainWidgetFunction-> funBackStartPoint();
        break;
    case FUN_CHECKFRAME://边框检查
        m_pMainWidgetFunction->funBorderCheck();
        break;
    case FUN_FORWARDORBACK://前进回退
        funForwardOrBack();
        break;
    case FUN_PATTERN_PREVIEW://花样预览
    {
        slotShowPara("PREVIEW");
        QFileInfo fileInfo(m_curFilePath);
        QString suffix = fileInfo.suffix().toUpper();
        showDiffPara(suffix);//获取头文件中的数据
        showDiffPara(suffix,1);//获取
        slotSetPatternData();//设置花样数据并显示
    }
        break;
    case FUN_SIMULATEFRAME://空走边框
        m_pMainWidgetFunction->funSimulateFrame();
        break;
    case FUN_PROCESSRESET://流程复位
        m_pMainWidgetFunction->funProcessReset();
        break;
    case FUN_MANUALOIL://手动加油
        m_pMainWidgetFunction->funManualOil();
        break;
    case FUN_PATTERNSELECT://花样选择
        patternSelect();
        break;
    case FUN_SEWAUTOCHANGESHUTTLE://自动换梭
        m_pMainWidgetFunction->funChangeOneShuttle();
        break;
    case FUN_SEWBUFF://缝纫状态
        //        m_pMainWidgetFunction->funSewBuff();
        break;
    case FUN_SHUTTLEDISKBUFF://换梭盘状态
        //        m_pMainWidgetFunction->funShuttleDiskBuff();
        break;
    case FUN_BACKTHREADPOINT://回穿线点
        //        m_pMainWidgetFunction->funBackThreadPoint();
        break;
    case FUN_BACKZEROPOINT://回零点
        //        m_pMainWidgetFunction->funBackZeroPoint();
        break;
    case FUN_GOTO_FINISH://回结束点
        m_pMainWidgetFunction->funGotoFinish();
        break;
    case FUN_SHUTTLETOHEAD://将旋梭从梭盘到机头
        //        m_pMainWidgetFunction->funShuttleToHead();
        break;
    case FUN_HEADTOSHUTTLE://将旋梭从机头到梭盘
        //        m_pMainWidgetFunction->funHeadToShuttle();
        break;
    case FUN_COUNTRESET://底线计数清零
        m_pMainWidgetFunction->funBottomLineCountReset();
        break;
    case FUN_OUTPUTRESET://产量清零
        m_pMainWidgetFunction->funResetOutput();
        break;
    case FUN_NEDDLEZEROPOS://对针零位
        //        m_pMainWidgetFunction->funNeedleZeroPos();
        break;
    case FUN_SHUTTLEZEROPOS://对梭零位
        //        m_pMainWidgetFunction->funShuttleZeroPos();
        break;
        //启动工作
    case FUN_STARTWORK:
        m_pMainWidgetFunction->funStartWork();
        break;

    case FUN_SHUTTLE_REFUELING://梭加油
        m_pMainWidgetFunction->funShuttleRef();
        break;
    case FUN_NEEDLE_REFUELING://针加油
        m_pMainWidgetFunction->funNeedleRef();
        break;

    case FUN_MT_ALLZ://所有主轴零位
        m_pMainWidgetFunction->funAllMtZero();
        break;
    case FUN_MT_ALLG://所有主轴勾线
        m_pMainWidgetFunction->funAllMtG();
        break;
    case FUN_MT_ALLM://所有主轴点动
        m_pMainWidgetFunction->funAllMtM();
        break;
    case FUN_MAINSHAFT_ADJUST:  // 针梭校对
        m_pMainWidgetFunction->funMainshaftAdjust();
        break;
    case FUN_SPINDLETEST:// 所有主轴研车
        m_pMainWidgetFunction->funAllMainShaftRun();
        break;
    case FUN_SIMULATED_STATUS://模拟缝纫
        m_pMainWidgetFunction->funSimulatedSewing();
        break;
    case FUN_MANUAL_THREAD_CUTTING://手动剪线
        m_pMainWidgetFunction->manualThreadCutting();
        break;
    case FUN_HEAD_LIFTUPDOWN://机头升降
        m_pMainWidgetFunction->headLiftUpDown();
        break;
    case FUN_HEAD_LIFTING://机头上升
        m_pMainWidgetFunction->headLifting();
        break;
    case FUN_GOTO_FEEDT://回穿线点
        g_pMachine->gotoFixPos();
        break;
    case FUN_MAKEUP_NOHEAD:// 取消补缝
        m_pMainWidgetFunction->makeup(MAKEUP_NOHEAD);
        break;
    case FUN_MAKEUP_HEAD1:// 机头1补缝
        m_pMainWidgetFunction->makeup(MAKEUP_HEAD1);
        break;
    case FUN_MAKEUP_HEAD2:// 机头2补缝
        m_pMainWidgetFunction->makeup(MAKEUP_HEAD2);
        break;
    case FUN_MAKEUP_HEAD3:// 机头3补缝
        m_pMainWidgetFunction->makeup(MAKEUP_HEAD3);
        break;
    case FUN_MAKEUP_HEAD4:// 机头4补缝
        m_pMainWidgetFunction->makeup(MAKEUP_HEAD4);
        break;
    case FUN_MAKEUP_HEAD5:// 机头5补缝
        m_pMainWidgetFunction->makeup(MAKEUP_HEAD5);
        break;
    case ASSIST_ThCutAct1://机头1 剪线动作
        g_pMachine->motoServoCtrl(ThreadCuttingAction1, UP_OPEN_ON);
        break;
    case ASSIST_ThCutAct2:
        g_pMachine->motoServoCtrl(ThreadCuttingAction2, UP_OPEN_ON);
        break;
    case ASSIST_ThCutAct3:
        g_pMachine->motoServoCtrl(ThreadCuttingAction3, UP_OPEN_ON);
        break;
    case ASSIST_ThCutAct4:
        g_pMachine->motoServoCtrl(ThreadCuttingAction4, UP_OPEN_ON);
        break;
    case ASSIST_ThCutAct5:
        g_pMachine->motoServoCtrl(ThreadCuttingAction5, UP_OPEN_ON);
        break;
    case FUN_SETANCHORPOINT:// 定定位点（服装机）
        m_pMainWidgetFunction->funSetAnchorPoint(m_curFilePath,m_mcStatus.xPos,m_mcStatus.yPos,1);
        break;
    case FUN_FLAT_SETANCHORPOINT:// 定定位点（平板切割）
        //平板切割机回工作点时需要把工作点坐标设置为定位点
        if(g_emMacType == MACHINE_FLATCUTTINGMAC
                || g_emMacType == MACHINE_FLYFLATCUTTING
                || g_emMacType == MACHINE_DRAWING)
        {
            int x = m_mcStatus.xPos;
            int y = m_mcStatus.yPos;
            m_pMainWidgetFunction->funSetAnchorPointForFlat(m_curFilePath,x,y,1,1);
            int begX = g_pCurEmbData->getBeginX();
            int begY = g_pCurEmbData->getBeginY();

            QString startStr = QString("%1/%2").arg(QString::number(begX/100,'f',2)).arg(QString::number(begY/100,'f',2));
            ui->lab_StartPoint_2->setText(startStr);
            ui->lab_Range_2->setText(QString("%1,%2/%3,%4")
                                     .arg(g_pCurEmbData->getMinX()/100)
                                     .arg(g_pCurEmbData->getMaxX()/100)
                                     .arg(g_pCurEmbData->getMinY()/100)
                                     .arg(g_pCurEmbData->getMaxY()/100));
        }
        break;
    case FUN_BACKANCHORPOINT://回定位点
        m_pMainWidgetFunction-> funBackAnchorPoint();
        break;
    case FUN_BACKSHUTTLE://回换梭位
        m_pMainWidgetFunction->funBackShuttlePos();
        break;
    case FUN_NEEDLESHUTTLERESET://针梭校对
        m_pMainWidgetFunction->funNeedleShuttleReset();
        break;
    case FUN_KNIFE_COLLECT://刀压采集
        m_pMainWidgetFunction->funKnifeCollect();
        break;
    case FUN_KNIFE_TEST://刀压测试
        m_pMainWidgetFunction->funKnifeTest();
        break;
    case FUN_FAN_AREA://风机区域
        m_pMainWidgetFunction->funFanArea();
        break;
    case FUN_SPD_SELECT://速度选择
        m_pMainWidgetFunction->funSpdSelect();
        break;
    case FUN_SET_KNIFETEST_POS://设置刀压检测位置
        m_pMainWidgetFunction->funSetKnifeTestPos();
        break;
    case FUN_SET_KNIFEROT_POS://设置被动刀旋转位置
        m_pMainWidgetFunction->funSetKnifeRotPos();
        break;
    case FUN_ROT_PASSIVE_KNIFE://旋转被动刀
        m_pMainWidgetFunction->funRotPassiveKnife();
        break;
    case FUN_ROT_PASSIVE_KNIFE1://旋转被动刀1
        m_pMainWidgetFunction->funRotPassiveKnife1();
        break;
    case FUN_ROT_PASSIVE_KNIFE2://旋转被动刀2
        m_pMainWidgetFunction->funRotPassiveKnife2();
        break;
    case FUN_CROSS_CUT://横切
        m_pMainWidgetFunction->funCrossCut();
        break;
    case FUN_DISPLAY_COLLECTED_DATA://显示采集数据
        g_pMachine->getParasFromMachine(DCMD_SEND_MOTO_GAINPARA);
        m_pKnifeGapParaDlg.data()->show();
        break;
        //主轴去指定角度
    case FUN_MS_TO_ANGLE:
        m_pMainWidgetFunction->funSpindleRotate();
        break;

        // 所有主轴研车
    case FUN_WIRE_MS_RUN:
        m_pMainWidgetFunction->funAllMainShaftRun();
        break;

        //旋转电机去指定角度
    case FUN_ROT_TO_ANGLE:
        m_pMainWidgetFunction->funRotateRotate();
        break;

        //自动拉料
    case FUN_AUTO_PULL:
        m_pMainWidgetFunction->AutomaticMaterialPull();
        break;

        //剪底面线
    case FUN_CUT_UD:
        m_pMainWidgetFunction->CutBottomLine();
        break;

        //剪电阻丝
    case FUN_CUT_WIRE:
        m_pMainWidgetFunction->CutResistanceWire();
        break;

        //回拉料起始点
    case FUN_GOTO_PULLPOS:
        m_pMainWidgetFunction->StartPointOfBackMaterial();
        break;

        //夹布工作状态
    case FUN_JAW_WORK:
        m_pMainWidgetFunction->WorkStatusOfClamp();
        break;

        //夹布上料状态
    case FUN_JAW_FEED:
        m_pMainWidgetFunction->ClothStatus();
        break;

        //去摆动位1
    case FUN_ZIGZAG_POS1:
        m_pMainWidgetFunction->SwingPositionOne();
        break;

        //去摆动位2
    case FUN_ZIGZAG_POS2:
        m_pMainWidgetFunction->SwingPositionTwo();
        break;

        //手动拉料
    case FUN_YPB_MOVE:
        m_pMainWidgetFunction->ManualMaterial();
        break;

        //自动换一个梭
    case FUN_AUTO_CHANGE_ONE_SHUT:
        m_pMainWidgetFunction->funChangeOneShuttle();
        break;

        //安装第一个梭壳
    case FUN_INSTALL_FIRST_BOBBIN:
        m_pMainWidgetFunction->InstallTheFirstShuttleShell();
        break;

        //将旋梭从梭盘拿到机头
    case FUN_SHUT_FROM_PLATE_TO_HEAD:
        m_pMainWidgetFunction->ShuttleFromTrayToHead();
        break;

        //将旋梭从机头拿到梭盘
    case FUN_SHUT_FROM_HEAD_TO_PLATE:
        m_pMainWidgetFunction->ShuttleFromHeadToTray();
        break;

        //进入更换梭盘状态
    case FUN_SHUT_INTO_TAKE_PLATE:
        m_pMainWidgetFunction->ShuttleState();
        break;

        //进入缝纫状态
    case FUN_SHUT_INTO_INDX_STA:
        m_pMainWidgetFunction->SewState();
        break;

        //进入缝纫状态
    case FUN_SHUT_FEED_STATE:
        m_pMainWidgetFunction->FeedState();
        break;

        //进入缝纫状态
    case FUN_SHUT_BACK_STATE:
        m_pMainWidgetFunction->BackState();
        break;

        //梭芯底线显示
    case FUN_SHUIILE_LINE:
        m_pMainWidgetFunction->ShuttleBottemLine();
        break;

    default:
        break;
    }
}

//执行辅助按钮功能
void MainWidget::runAssistBtnFunction(int funEnum,int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }
    unsigned char cmd[6]{0X04,0xE4,0x04,0x00,0xFF,0x14}; //启动扫码器的指令
    QByteArray scanCmd((const char*)cmd,6);
    QString topImageName = m_assistItemList[idx].m_topImageName;
    //加载按钮顶图图标
    QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);

    switch (funEnum)
    {
    case ASSIST_SENSOR://传感器信号
    {
        if (m_pSensorInputWi != NULL)
        {
            //注释掉此行代码，因为获取位图下位机会返回全on的状态，
            //会使传感器界面闪一下，在连接后读取了一下，这里不再读取
            //g_pMachine->getSensorEnBmpFromMachine();
            g_pMachine->entrySensorScan();

            m_pSensorInputWi->setTypeLogo(tStyle);
            m_pSensorInputWi->setMainTitle(tr("Sensor signal"));
            m_pSensorInputWi->setSubTitle(tr("Auxiliary function > Sensor signal"));
            m_pSensorInputWi->show();
        }
    }
        break;

    case ASSIST_CONTROLACTION://控制动作
    {
        if (m_pControlActionWi != NULL)
        {
            m_pControlActionWi->setTypeLogo(tStyle);
            m_pControlActionWi->setMainTitle(tr("Control action"));
            m_pControlActionWi->setSubTitle(tr("Auxiliary function > Control action"));

            m_pControlActionWi->refreshUi();
            m_pControlActionWi->show();
        }
    }
        break;

    case ASSIST_HMIUPGRADE://界面升级
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                return;
        }
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funHMIUpgrade(tStyle);
        }

    }
        break;

    case ASSIST_HMIBACKUPSUPGRADE://界面还原
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                return;
        }
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funHMIBackupsUpgrade(tStyle);
        }

    }
        break;

    case ASSIST_MCUPGRADE://主控升级
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                return;
        }

        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funMCUpgrade(tStyle);
        }
    }
        break;


    case ASSIST_PARAIMPORT://参数导入
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;//就不执行下边的代码，不显示界面
            }
        }
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funImportParameter(tStyle);
        }
    }
        break;

    case ASSIST_PARAEXPORT://参数导出
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        g_pMachine->getInfoFromMachine();
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funExportParameter();
        }
    }
        break;

    case ASSIST_SOFTWARESET://软件设置
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Accessibility"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Software setting"));
        //软件设置参数
        //        m_pParameterSetDlg->setItemValue(SET_THEME,g_emTheme);     //主题
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_SOFTWARESET);
        int language = g_pSettings->readFromIniFile("HMI/language").toInt();
        m_pParameterSetDlg->setItemValue(SET_LANGUAGE,language);  //语言

        int frontsize = g_pSettings->readFromIniFile("HMI/FrontSize").toInt();
        m_pParameterSetDlg->setItemValue(SET_FONTSIZE,frontsize);  //字体大小

        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_AUTHORIZATION://软件授权
    {
        m_pMainWidgetFunction->funSoftwareAuthor();
    }
        break;

    case ASSIST_NETWORK://网络管理
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Accessibility"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Network Manage"));

        //网络管理参数
        //添加相应主板数的IP参数
        m_pParameterSetDlg->setNetworkItemList(PARA_TYPE_NETWORKSET);
        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_WIFI:
    {
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funWIFI(tStyle);
        }
    }
        break;
    case ASSIST_TIMESET://时间设置
    {
        //得到当前时间
        QDateTime time;
        time = QDateTime::currentDateTime();//获取系统现在的时间

        QString yearStr = time.currentDateTime().toString("yyyy");
        QString monthStr = time.currentDateTime().toString("MM");
        QString dayStr = time.currentDateTime().toString("dd");
        QString hourStr = time.currentDateTime().toString("hh");
        QString minuteStr = time.currentDateTime().toString("mm");
        QString secondStr = time.currentDateTime().toString("ss");

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Time setting"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Time setting"));
        //时间设置参数
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_TIMESET);
        m_pParameterSetDlg->setItemValue(1,yearStr.toInt());   //年
        m_pParameterSetDlg->setItemValue(2,monthStr.toInt());   //月
        m_pParameterSetDlg->setItemValue(3,dayStr.toInt());   //日
        m_pParameterSetDlg->setItemValue(4,hourStr.toInt());   //时
        m_pParameterSetDlg->setItemValue(5,minuteStr.toInt());   //分
        m_pParameterSetDlg->setItemValue(6,secondStr.toInt());   //秒

        m_pParameterSetDlg->exec();
    }
        break;

    case ASSIST_PRODUCTSTATICS://生产统计
    {
        int patternBreakLineNum = 0;//花样断线停车次数
        m_pMainWidgetFunction->funProductStatistics(tStyle,m_curFilePath,patternBreakLineNum);
    }
        break;


    case ASSIST_ERRORLOG://错误日志
    {
        if(g_emDebugMode == nodebugMode && g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                return;
        }
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funJournalError(tStyle);
        }

    }
        break;

    case ASSIST_MCVERSION://N1版本信息
    {
        g_pMachine->getInfoFromMachine();
        m_pMainWidgetFunction->funGetMCVersionInfo();
    }
        break;

    case ASSIST_BOTTOMLINEDETECT://底线检测
    {
        m_pMainWidgetFunction->funBottomDetect();
    }
        break;

    case ASSIST_FACELINEDETECT://面线检测
    {
        m_pMainWidgetFunction->funFaceDetect();
    }
        break;

    case ASSIST_SPINDLETEST://主轴研车(试机)
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Spindle test"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Spindle test"));

        //超级用户参数
        m_pParameterSetDlg->setItemList(-1,operate,PARA_TYPE_SPINDLETEST);
        if(m_pParameterSetDlg->exec() == 1)
        {
            s32 para1 = m_pParameterSetDlg->getItemValue(1);
            s32 para2 = m_pParameterSetDlg->getItemValue(2);

            if(g_pMachine != NULL)
            {
                g_pMachine->embSpindleTest(para1,para2);
            }
        }
    }
        break;

    case ASSIST_CHANGEASHUTTLE:    //自动换一个梭
        m_pMainWidgetFunction->funChangeOneShuttle();
        break;

    case ASSIST_ROOT://超级用户
    {
        if(g_emDebugMode == nodebugMode && g_emUser != root)//超级用户
        {
            m_pMainWidgetFunction->slotUserLogin(root);
            if(g_emUser != root)//发送登录信号后，权限如果还没改变就返回
                return;
        }

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Root"));
        m_pParameterSetDlg->setSubTitle(tr("Accessibility > Root"));
        //超级用户参数
        m_pParameterSetDlg->setItemList(root,PARA_TYPE_ROOT);
        m_pParameterSetDlg->exec();

    }
        break;

    case ASSIST_BOTTOMLINECOUNTRESET://底线计数复位
    {
        if(m_pMainWidgetFunction != NULL)
        {
            m_pMainWidgetFunction->funBottomLineCountReset();
        }
    }
        break;

    case ASSIST_DEBUGINFO:    //调试信息
        m_pMainWidgetFunction->funDebugInfo();
        break;

    case ASSIST_SHUTDOWN:    //关机
        m_pMainWidgetFunction->funShutDown();
        break;

    case ASSIST_ScanTest:    //扫码测试
        qDebug()<<"scanCmd send" << scanCmd.data();
        QMetaObject::invokeMethod(m_pScanComPort,"slotSendData",Q_ARG(QByteArray,scanCmd));
        break;
    default:
        break;
    }
}

//执行花样设置按钮功能
void MainWidget::runPatternSetBtnFunction(int funEnum, int idx)
{
    if(m_pMainWidgetFunction == NULL)
    {
        return;
    }

    QString topImageName = m_patternSetItemList[idx].m_topImageName;
    //加载按钮顶图图标
    QString tStyle = m_setControlStyle.getTopStyleSheet(topImageName);
    //QString bStyle = m_setControlStyle.getBottomStyleSheet(ui->buttonAssist1->parent()->objectName());

    switch (funEnum)
    {
    case PATTERNSET_PATTERNSELECT://花样选择
        patternSelect();
        break;

    case PATTERNSET_PATTERNPARA://花样参数
        //showPatternPreview();
        slotShowPatternPara(m_curFilePath);
        break;

    case PATTERNSET_ALGORITHMPARA://分割参数
        slotShowPara("PLT");
        break;

    case PATTERNSET_PATTERNIMPORT://花样导入
    {
        m_pPatternManageWi->setTypeLogo(tStyle);
        m_pPatternManageWi->setMainTitle(tr("Pattern import"));
        m_pPatternManageWi->setSubTitle(tr("Pattern setting > Pattern import"));

        PatternManageWidget::MANAGE_MODE mode = PatternManageWidget::MANAGE_IMPORT;

        QSize size = m_pPatternSelectWi->getImageSize();
        m_pPatternManageWi->setImportImageSize(size);
        m_pPatternManageWi->patternManage(mode);
    }
        break;

    case PATTERNSET_PATTERNEXPORT://花样导出
    {
        m_pPatternManageWi->setTypeLogo(tStyle);
        m_pPatternManageWi->setMainTitle(tr("Pattern export"));
        m_pPatternManageWi->setSubTitle(tr("Pattern setting > Pattern export"));

        PatternManageWidget::MANAGE_MODE mode = PatternManageWidget::MANAGE_EXPORT;
        m_pPatternManageWi->patternManage(mode);
    }
        break;

    case PATTERNSET_PATTERNDELETE://花样删除
    {
        if(g_emUser != repair)//权限不够先登录
        {
            m_pMainWidgetFunction->slotUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        m_pPatternManageWi->setTypeLogo(tStyle);
        m_pPatternManageWi->setMainTitle(tr("Pattern delete"));
        m_pPatternManageWi->setSubTitle(tr("Pattern setting > Pattern delete"));

        PatternManageWidget::MANAGE_MODE mode = PatternManageWidget::MANAGE_DELETE;
        m_pPatternManageWi->patternManage(mode);
    }
        break;

    case PATTERNSET_PATTERNPREVIEW://花样预览
    {
        slotShowPara("PREVIEW");
        QFileInfo fileInfo(m_curFilePath);
        QString suffix = fileInfo.suffix().toUpper();
        showDiffPara(suffix);
        showDiffPara(suffix,1);
        slotSetPatternData();//设置花样数据并显示
    }
        break;

    default:
        break;
    }

}

//等待超时
void MainWidget::slotWaitTimout()
{
    m_timoutflag = 1;
}

//机器状态
void MainWidget::slotMachineStatus(int toggle)
{
    memcpy(&m_mcStatus, &g_pMachine->getMcStatus(), sizeof(MCStatus));

    if(m_pMainWidgetFunction != NULL)
    {
        //收到主控发的机器状态改变的信号，进到这个槽函数里(在MainWidgetFunction.cpp里用于读取电位器值)
        m_pMainWidgetFunction->setMcStates(m_mcStatus);
    }
    m_conFlag = toggle;

    showExecInfo();//显示机器运行状态中的信息

    //工作状态，工作中按钮不可按，并显示大图
    if(m_workStatus != m_mcStatus.workStatus)
    {
        m_workStatus = m_mcStatus.workStatus;

        if ((m_workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
        {
            ui->labelWorkState->setStyleSheet(warnTextColour());
            ui->labelWorkState->setText(tr("Simulated working"));//模拟工作
            ui->labelWorkState->setVisible(true);
        }
        else //正常工作
        {
            ui->labelWorkState->setStyleSheet(titleTextColour());
            ui->labelWorkState->setText(tr("Normal operation"));//正常工作
            ui->labelWorkState->setVisible(true);
        }

        //开始扫码
        if((m_workStatus & WORK_STA_EN_SCAN) == WORK_STA_EN_SCAN)
        {
            qDebug()<< "WORK_STA_EN_SCAN   true";
            unsigned char cmd[6]{0X04,0xE4,0x04,0x00,0xFF,0x14}; //启动扫码器的指令  详见文档ScanHome扫码器指令控制设置-V4.0
            QByteArray scanCmd((const char*)cmd,6);
            QMetaObject::invokeMethod(m_pScanComPort,"slotSendData",Q_ARG(QByteArray,scanCmd));
        }

        //正在工作,按钮不可按
        if((m_workStatus & WORK_STA_WORKING) == WORK_STA_WORKING)
        {
            qDebug()<< "正在工作";
            if(g_emMacType != MACHINE_FLATCUTTINGMAC || g_emMacType != MACHINE_FLYFLATCUTTING)
                showSpeedFrame();
            setUiBtnEnable(false);

            //不是执行状态，重置
            setNotExecing();

            if(!ui->labelPatternView->isVisible())//不是主图灰图界面
            {
                hideMenuFrame();
                showPatternPreview();
                ui->buttonMainMenu->setCheckable(true);
                ui->buttonMainMenu->setChecked(true);
            }

            //如果工作中错误提示窗体显示，则自动消失
            m_pMainWidgetFunction->funSetPromptDlgVisibleFalse();
        }
        else
        {
            if(g_emMacType != MACHINE_FLATCUTTINGMAC || g_emMacType != MACHINE_FLYFLATCUTTING)
                showNineFrame();
            setUiBtnEnable(true);
        }
    }

    //错误代码
    if (m_mcStatus.errorCode == 0)
    {
        m_errorCode = m_mcStatus.errorCode;
        ui->labelState->setText(tr("Ready"));//状态：已就绪
        ui->labelState->setStyleSheet(titleTextColour_Green());//绿色文本
        if((m_workStatus & WORK_STA_WORKING) == WORK_STA_WORKING)
        {
            ui->labelState->setText(tr("Working"));//状态: 工作中
            ui->labelState->setStyleSheet(titleTextColour_Yellow());//黄色文本
        }
    }
    else
    {
        u32 errcode = m_mcStatus.errorCode;
        if(errcode != m_errorCode)
        {
            m_errorCode = errcode;

            QString info;
            info.clear();
            info = getErrStr(m_mcStatus.errorCode);
            //如果不是通用错误(即info为空)，就从机型cpp中的错误代码查找
            if(info.length() <= 0)
            {
                for(int i = 0; i < m_errorCodeAndStateItemList.size(); i++)
                {
                    if(m_mcStatus.errorCode == m_errorCodeAndStateItemList[i].m_code)
                    {
                        info = m_errorCodeAndStateItemList[i].m_name;
                        break;
                    }
                }
            }
            //如果不是通用错误也不是机型cpp中的错误代码，就显示未定义错误
            if(info.length() <= 0)
            {
                QString errorCode;
                errorCode.sprintf("CODE 0x%x", m_mcStatus.errorCode);
                info.append(tr("Undefined error,") + errorCode);//未定义错误,
            }

            ui->labelState->setStyleSheet(titleTextColour_Yellow());//红色文本
            ui->labelState->setText(info);//状态:

            if ((errcode > 0 && errcode < 0x100) || errcode > 0x200)
            {
                m_pMainWidgetFunction->funErrorPrompt(info);
                //将报错代码写入csv
                g_pSettings->writeToCsv(info,TYPE_ERROR);//保存
            }
            else
            {
                if(m_mcStatus.errorCode == STA_LINE_TBREAK)
                {
                    //检测断线状态
                    int ret = m_pMainWidgetFunction->funDetectBreakLineStatus();
                    if(ret != 0)//断线报错
                    {

                    }
                }
            }
        }
    }
}

void MainWidget::slotShowPercentage(int val)
{
    ui->labelTitle->setText(QString::number(val)+"%");
}

void MainWidget::slotRefreshWifiIcon(bool bl)
{
    if(bl == true)//已连接
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Connect"));
    }
    else
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Unconnect"));
    }
}

void MainWidget::slotShowPatternPara(QString filePath,s16 showFlag)
{
    QString beforeFilePath = m_curFilePath;
    qDebug()<<m_curFilePath;
    m_curFilePath = filePath;
    if(m_curFilePath.length() <= 0){return;}
    QFile file(m_curFilePath);
    if(!file.exists()){return;}//文件不存在

    //获得花样参数的图标
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            break;
        }
    }

    HeadSpacingSheetDialog headDialog(this);

    if(g_emMacType == MACHINE_FIVEHEADPRECISIONSEWING ){
        headDialog.setMainTitle(tr("Pattern para"));//花样参数
        headDialog.setSubTitle(tr("Pattern setting > Head spacing"));// 花样设置 > 机头间距
        headDialog.initDsrFileInfo(m_curFilePath);
        headDialog.setTypeLogo(tStyle);

        if((showFlag == 0) && ("DSR" == QFileInfo(filePath).suffix().toUpper()))
        {
            //执行修改机头间距界面
            int result = headDialog.exec();
            if(result != 1)
            {
                //点击取消按钮后花样路径恢复为上次选中的花样
                m_curFilePath = beforeFilePath;
                return;
            }
        }
    }

    m_pParameterSetDlg->setTypeLogo(tStyle);
    m_pParameterSetDlg->setMainTitle(tr("Pattern para"));//花样参数
    m_pParameterSetDlg->setSubTitle(tr("Pattern setting > Pattern para"));// 花样设置 > 花样参数

    QFileInfo fileInfo(m_curFilePath);
    QString suffix = fileInfo.suffix().toUpper();
    //为plt文件时不显示花样参数设置窗体
    if(suffix != "PLT")
    {
        showDiffPara(suffix);//根据文件格式不同显示不同花样参数
    }
    else
    {
        memset((char*)&m_patternSetPara,0,sizeof(PatternSetPara));
        showFlag = 1;
    }
    m_pParameterSetDlg->setCurPage(1);

    s16 value = 0;
    if(showFlag != 0)//不显示此窗体直接加载花样参数(适用于开机自动加载花样文件)
    {
        value = 1;
        m_pPatternSelectWi->hide();
    }
    else //显示此窗体
    {
        value = m_pParameterSetDlg->exec();
        m_pPatternSelectWi->hide();

#if(0)//昆仑通态操作屏下有问题，所以注释掉
        if(value == 1)
        {
            //正在加载花样提示窗体
            m_pPromptDlg->initDialog(PromptDialog::BTN_NONE);
            m_pPromptDlg->setTitleStr(tr("Prompt"));
            m_pPromptDlg->setContentStr(tr("Loading patterns, please wait..."));  //正在加载花样，请等待...
            m_pPromptDlg->show();
            QCoreApplication::processEvents(QEventLoop::AllEvents);
        }
#endif
    }

    if(value == 1)//花样参数设置(点击了确定按钮或直接加载文件后加载花样参数)
    {
        //TODO 机头列表界面设置

        //快进快退等功能可用
        for(int i = 0; i < m_quickItemList.size(); i++)
        {
            int enumFun = m_quickItemList[i].m_enumFunction;
            if(enumFun == FUN_FORWARDORBACK ||//快进快退
                    enumFun == FUN_SETSTARTPOINT ||//定起始点
                    enumFun == FUN_BACKSTARTPOINT ||//回起始点
                    enumFun == FUN_CHECKFRAME //边框检查
                    )
            {
                if(m_curFilePath.length() > 0)//选择文件后快进快退等按钮可用
                {
                    m_quickBtnList[i]->setEnabled(true);
                }
            }
        }

        //有花样时花样参数、花样色序、可按
        for(int i = 0; i < m_patternSetItemList.size(); i++)
        {
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
            {
                m_patternSetBtnList[i]->setEnabled(true);
            }
        }

        //为plt文件时不显示花样参数设置窗体，且不设置参数
        if(suffix != "PLT")
        {
            showDiffPara(suffix,1);
        }

        slotSetPatternData();//设置花样数据并显示

#if(0)//昆仑通态操作屏下有问题，所以注释掉
        if(m_pPromptDlg->isVisible())//若是可见的
        {
            m_pPromptDlg->hide();//隐藏加载花样的提示窗体
        }
#endif

        //发送五头机机头间距数据
        if((m_linkSta == Connected) && (g_emMacType == MACHINE_FIVEHEADPRECISIONSEWING)){
            g_pMachine->setHeadSpacing(headDialog.getHeadData());
        }

        //计算起始点和定位点并设置
        calPointsAndSet(m_backPosFlag);

        ui->lab_Locate_2->setText(QString("%1/%2")
                                  .arg(QString::number((double)m_patternSetPara.left/10,'f',1))
                                  .arg(QString::number((double)m_patternSetPara.front/10,'f',1))); //定位点 从左边前边获取
        ui->lab_StartPoint_2->setText(QString("%1/%2")
                                      .arg(QString::number((double)m_patternSetPara.startX/100,'f',2))
                                      .arg(QString::number((double)m_patternSetPara.startY/100,'f',2)));
        ui->lab_Range_2->setText(QString("%1,%2/%3,%4")
                                 .arg(g_pCurEmbData->getMinX()/100)
                                 .arg(g_pCurEmbData->getMaxX()/100)
                                 .arg(g_pCurEmbData->getMinY()/100)
                                 .arg(g_pCurEmbData->getMaxY()/100));

        if(m_linkSta == Connected)//已连接
        {
            m_pMainWidgetFunction->sendPatternData(m_curFilePath);//发送花样数据
            //设置为按进度执行模式
            g_pCurEmbData->setExecIndex(m_curDatIdx);     // 设置进度
        }
    }
    else
    {
        //点击取消按钮后花样路径恢复为上次选中的花样
        m_curFilePath = beforeFilePath;
    }
}

void MainWidget::slotShowPara(QString suffix)
{
    //获得花样参数的图标
    QString tStyle;
    for(int i = 0; i < m_patternSetItemList.size(); i++)
    {
        if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_ALGORITHMPARA)
        {
            QString topImageName = m_patternSetItemList[i].m_topImageName;
            //加载按钮顶图图标
            tStyle = m_setControlStyle.getTopStyleSheet(topImageName);
            break;
        }
    }

    showDiffPara(suffix);// 显示不同花样的参数
    m_pParameterSetDlg->setItemValue(FIT_SMALL, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutMinstStp").toInt());                 //拟合小针步
    m_pParameterSetDlg->setItemValue(MINIMUM_STEP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutLineMinStp").toInt());                 //直线最小步长
    m_pParameterSetDlg->setItemValue(MAXIMUM_STEP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutLineMaxStp").toInt());                 //直线最大步长
    m_pParameterSetDlg->setItemValue(JUDGMENT_DEGREE, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutRoudAng").toInt());                 //圆弧转角判断度数
    m_pParameterSetDlg->setItemValue(ARC_COMPENSATION, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutRoudStp").toInt());                 //圆弧补偿步长
    m_pParameterSetDlg->setItemValue(ARC_COMPENSATION_1, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cut1Radius").toInt());                 //切刀1圆弧补偿半径
    m_pParameterSetDlg->setItemValue(ARC_COMPENSATION_2, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cut2Radius").toInt());                 //切刀2圆弧补偿半径

    m_pParameterSetDlg->setItemValue(CUT_SPD_MINPPS, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutSpdMinpps").toInt());                 //最小切割速度
    m_pParameterSetDlg->setItemValue(CUT_SPD_MAXPPS, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutSpdMaxpps").toInt());                 //最大切割速度
    m_pParameterSetDlg->setItemValue(CUT_ADD_PPSG, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutAddPpsg").toInt());                           //切割加速度
    m_pParameterSetDlg->setItemValue(CUT_SLOW_ANGLE, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutSlowAngle").toInt());                 //切割降速最小偏差角度
    m_pParameterSetDlg->setItemValue(CUT_WORK_MINADD, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutWorkMinadd").toInt());                 //工作最小加速度

    m_pParameterSetDlg->setItemValue(CUT_RNF1_COMP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutRnf1Comp").toInt());
    m_pParameterSetDlg->setItemValue(CUT_RNF2_COMP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutRnf2Comp").toInt());

    //飞行切割平板切割机
    if(g_emMacType == MACHINE_FLYFLATCUTTING)
    {
        m_pParameterSetDlg->setItemValue(CUT_CRUTCH_ANG, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutCrutchAng").toDouble());    //拐点转角判断度数
        m_pParameterSetDlg->setItemValue(CUT_LINE_STP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutLineStp").toInt());        //分割数据步长
        m_pParameterSetDlg->setItemValue(CUT_X_LENGH, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutXLengh").toInt());          //X向可切割长度
        //    m_pParameterSetDlg->setItemValue(CUT_X_WINDOW, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutXWindow").toInt());        //X向过窗长度
        //    m_pParameterSetDlg->setItemValue(CUT_X_EDGE, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutXEdge").toInt());            //X向过窗边缘
        m_pParameterSetDlg->setItemValue(CUT_RNF_COMP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutRnfComp").toInt());        //圆刀退刀补偿
        m_pParameterSetDlg->setItemValue(CUT_Vert_COMP, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutVertComp").toInt());        //切割垂直补偿
        m_pParameterSetDlg->setItemValue(CUT_ENABLE_BRUSH, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutEnableBrush").toInt());        //画笔启用
        m_pParameterSetDlg->setItemValue(CUT_ENABLE_OR, g_pSettings->readFromIniFile("FlatPanelAlgorithm/AreParallel").toInt());        //重叠消除启用
        m_pParameterSetDlg->setItemValue(CUT_ENABLE_DELEDGE, g_pSettings->readFromIniFile("FlatPanelAlgorithm/delEdge").toInt());        //边界消除启用
        m_pParameterSetDlg->setItemValue(CUT_DELEDGE_VALUE, g_pSettings->readFromIniFile("FlatPanelAlgorithm/DelEdgeValue").toInt());        //边界消除误差
        m_pParameterSetDlg->setItemValue(CUT_OR_VALUE, g_pSettings->readFromIniFile("FlatPanelAlgorithm/ORVALUE").toInt());        //重叠消除误差
    }

    //多针旋梭机
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        m_pParameterSetDlg->setItemValue(PV_SPINDLE_TYPE, g_pSettings->readFromIniFile("PatternPreView/SpindleType").toInt());      //主轴类型
        m_pParameterSetDlg->setItemValue(PV_NEEDLE_SPACING, g_pSettings->readFromIniFile("PatternPreView/NeedleSpacing").toInt());  //针间距
        m_pParameterSetDlg->setItemValue(PV_SPACING_BETWEEN_NEEDLE_ROWS, g_pSettings->readFromIniFile("PatternPreView/NeedleRowsSpacing").toInt()); //排针间距
        m_pParameterSetDlg->setItemValue(PV_LOWER_ROW_HEAD_CENTERED, g_pSettings->readFromIniFile("PatternPreView/HeadCentered").toInt());          //下排机头居中
    }

    //    m_pParameterSetDlg->setItemValue(CUT_OFFSET_SPD, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutOffsetSpd").toInt());    //偏移速度
    //    m_pParameterSetDlg->setItemValue(CUT_DRAWING_SPD, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutDrawingSpd").toInt());  //画笔速度
    //    m_pParameterSetDlg->setItemValue(CUT_CUTTING_SPD, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutCuttingSpd").toInt());  //切割速度
    //    m_pParameterSetDlg->setItemValue(CUT_LEFT_TIME, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutLeftTime").toInt());      //升降机头时间
    //    m_pParameterSetDlg->setItemValue(CUT_SPD_ADJ, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutSpdAdj").toInt());          //行进速度校准
    //    m_pParameterSetDlg->setItemValue(CUT_SPD_MAX, g_pSettings->readFromIniFile("FlatPanelAlgorithm/cutSpdMax").toInt());          //最大行进速度

    if(suffix == "PREVIEW")
    {
        QString strLogo = m_setControlStyle.getTopStyleSheet("buttonPatternPreview");
        m_pParameterSetDlg->setTypeLogo(strLogo);
        m_pParameterSetDlg->setMainTitle(tr("Pattern para"));//花样参数
        m_pParameterSetDlg->setSubTitle(tr("Pattern setting > Pattern preview"));// 花样设置 > 花样预览
    }else
    {
        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Pattern para"));//花样参数
        m_pParameterSetDlg->setSubTitle(tr("Pattern setting > Pattern para"));// 花样设置 > 花样参数
    }
    m_pParameterSetDlg->setCurPage(1);
    int value = m_pParameterSetDlg->exec();

    if(value == 1)//花样参数设
    {
        //平板切割算法
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutMinstStp", m_pParameterSetDlg->getItemValue(FIT_SMALL));         // 拟合小针步
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutLineMinStp", m_pParameterSetDlg->getItemValue(MINIMUM_STEP));    // 直线最小步长
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutLineMaxStp", m_pParameterSetDlg->getItemValue(MAXIMUM_STEP));    // 直线最大步长
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutRoudAng", m_pParameterSetDlg->getItemValue(JUDGMENT_DEGREE));    // 圆弧转角判断度数
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutRoudStp", m_pParameterSetDlg->getItemValue(ARC_COMPENSATION));   // 圆弧补偿步长
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cut1Radius", m_pParameterSetDlg->getItemValue(ARC_COMPENSATION_1)); // 切刀1圆弧补偿半径
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cut2Radius", m_pParameterSetDlg->getItemValue(ARC_COMPENSATION_2)); // 切刀2圆弧补偿半径

        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutSpdMinpps", m_pParameterSetDlg->getItemValue(CUT_SPD_MINPPS));   //最小切割速度
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutSpdMaxpps", m_pParameterSetDlg->getItemValue(CUT_SPD_MAXPPS));   //最大切割速度
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutAddPpsg", m_pParameterSetDlg->getItemValue(CUT_ADD_PPSG));       //切割加速
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutSlowAngle", m_pParameterSetDlg->getItemValue(CUT_SLOW_ANGLE));   //切割降速最小偏差角度
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutWorkMinadd", m_pParameterSetDlg->getItemValue(CUT_WORK_MINADD)); //工作最小加速度
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutRnf1Comp", m_pParameterSetDlg->getItemValue(CUT_RNF1_COMP));     //起刀补偿
        g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutRnf2Comp", m_pParameterSetDlg->getItemValue(CUT_RNF2_COMP));     //落刀补偿

        //飞行切割平板切割机
        if(g_emMacType == MACHINE_FLYFLATCUTTING)
        {
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutCrutchAng", m_pParameterSetDlg->getItemValue(CUT_CRUTCH_ANG));    //拐点转角判断度数
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutLineStp", m_pParameterSetDlg->getItemValue(CUT_LINE_STP));        //分割数据步长
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutXLengh", m_pParameterSetDlg->getItemValue(CUT_X_LENGH));          //X向可切割长度
            //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutXWindow", m_pParameterSetDlg->getItemValue(CUT_X_WINDOW));        //X向过窗长度
            //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutXEdge", m_pParameterSetDlg->getItemValue(CUT_X_EDGE));            //X向过窗边缘
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutRnfComp", m_pParameterSetDlg->getItemValue(CUT_RNF_COMP));           //圆刀退刀补偿
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutVertComp", m_pParameterSetDlg->getItemValue(CUT_Vert_COMP));         //切割垂直补偿
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutEnableBrush", m_pParameterSetDlg->getItemValue(CUT_ENABLE_BRUSH));   //画笔启用
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/AreParallel", m_pParameterSetDlg->getItemValue(CUT_ENABLE_OR));             //重叠消除是否启用
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/delEdge", m_pParameterSetDlg->getItemValue(CUT_ENABLE_DELEDGE));            //边界消除是否启用
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/DelEdgeValue", m_pParameterSetDlg->getItemValue(CUT_DELEDGE_VALUE));        //边界消除误差值
            g_pSettings->writeToIniFile("FlatPanelAlgorithm/ORVALUE", m_pParameterSetDlg->getItemValue(CUT_OR_VALUE));                  //重叠消除误差值
        }

        //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutOffsetSpd", m_pParameterSetDlg->getItemValue(CUT_OFFSET_SPD));    //偏移速度
        //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutDrawingSpd", m_pParameterSetDlg->getItemValue(CUT_DRAWING_SPD));  //画笔速度
        //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutCuttingSpd", m_pParameterSetDlg->getItemValue(CUT_CUTTING_SPD));  //切割速度
        //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutLeftTime", m_pParameterSetDlg->getItemValue(CUT_LEFT_TIME));      //升降机头时间
        //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutSpdAdj", m_pParameterSetDlg->getItemValue(CUT_SPD_ADJ));          //行进速度校准
        //g_pSettings->writeToIniFile("FlatPanelAlgorithm/cutSpdMax", m_pParameterSetDlg->getItemValue(CUT_SPD_MAX));          //最大行进速度

        if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
        {
            g_pSettings->writeToIniFile("PatternPreView/SpindleType",m_pParameterSetDlg->getItemValue(PV_SPINDLE_TYPE));     //主轴类型
            g_pSettings->writeToIniFile("PatternPreView/NeedleSpacing",m_pParameterSetDlg->getItemValue(PV_NEEDLE_SPACING)); //针间距
            g_pSettings->writeToIniFile("PatternPreView/NeedleRowsSpacing",m_pParameterSetDlg->getItemValue(PV_SPACING_BETWEEN_NEEDLE_ROWS));//排针间距
            g_pSettings->writeToIniFile("PatternPreView/HeadCentered",m_pParameterSetDlg->getItemValue(PV_LOWER_ROW_HEAD_CENTERED));     //下排机头居中
        }
    }
}

void MainWidget::slotTcpRecvFile(QString filePath)
{
    qDebug()<< "tcp RecvFile : "<<filePath;
    slotShowPatternPara(filePath,-1);
}

//删除文件后判断当前文件是否被删除
void MainWidget::slotIfFileExist()
{
    if(m_curFilePath.length() > 0)
    {
        QFile file(m_curFilePath);
        if(!file.exists())//不存在
        {
            m_curFilePath.clear();

            //花样参数不可按
            for(int i = 0; i < m_patternSetItemList.size(); i++)
            {
                if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
                {
                    m_patternSetBtnList[i]->setEnabled(false);
                }
            }

            if(g_pMachine != NULL)
            {
                g_pMachine->invalidateWorkFile();
            }
        }
    }
}

//花样导入替换文件，判断替换文件是否是当前所选的花样
void MainWidget::slotReplacePattrn(QString path)
{
    QFileInfo file(m_curFilePath);
    QFileInfo newfile(path);
    QString pathPattern = file.fileName();
    QString newPathPattern = newfile.fileName();
    if(m_curFilePath.length() > 0)//当前选择的花样路径
    {
        if(pathPattern == newPathPattern)//如果替换的花样等于当前选择的花样
        {
            m_curFilePath.clear();//清空当前的花样，并重新选择

            //花样参数、花样色序不可按
            for(int i = 0; i < m_patternSetItemList.size(); i++)
            {
                if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA ||
                        m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNCOLOR)
                {
                    m_patternSetBtnList[i]->setEnabled(false);
                }
            }

            if(g_pMachine != NULL)
            {
                g_pMachine->invalidateWorkFile();
            }
        }
    }
}

void MainWidget::slotClearPatternFcg()
{
    if(m_curFilePath.length() > 0)//当前选择的花样路径
    {
        m_curFilePath.clear();

        //花样参数、花样色序不可按
        for(int i = 0; i < m_patternSetItemList.size(); i++)
        {
            if(m_patternSetItemList[i].m_enumFunction == PATTERNSET_PATTERNPARA)
            {
                m_patternSetBtnList[i]->setEnabled(false);
            }
        }

        for(int i = 0; i < m_quickItemList.size(); i++)
        {
            int enumFun = m_quickItemList[i].m_enumFunction;
            if(enumFun == FUN_FORWARDORBACK ||//快进快退
                    enumFun == FUN_SETSTARTPOINT ||//定起绣点
                    enumFun == FUN_BACKSTARTPOINT ||//回起绣点
                    enumFun == FUN_CHECKFRAME //边框检查
                    )
            {
                m_quickBtnList[i]->setEnabled(false);
            }
        }

        ui->buttonNineBtn1->setEnabled(false);

        if(g_pMachine != NULL)
        {
            g_pMachine->invalidateWorkFile();
        }
    }
}

//设置花样数据
void MainWidget::slotSetPatternData()
{
    if(m_curFilePath.length() <= 0)
    {
        return;
    }
    QFile curfile(m_curFilePath);
    if(!curfile.exists())
    {
        return;
    }

    if(m_pParameterSetDlg == NULL){return;}

    g_pCurEmbData->setViewInfo(m_embBackPix);
    g_pCurEmbData->setDrawMode(EmbData::DRAW_VIEW);//非预览模式
    QFileInfo file(m_curFilePath);
    QString ext = file.suffix().toUpper();
    QString fileName = file.fileName().left(file.fileName().size() - 4);//去掉结尾dsr
    ui->lab_FileName_2->setText(fileName); //去掉结尾的dsr
    g_pCurEmbData->clear();//清空当前选择的花样

    if(appendDiffAbsData(ext) != 0)
    {
        return;
    }

    g_pCurEmbData->appendAEmbAbsFile(m_curFilePath, g_pCurEmbData->getAbsDat());//生成文件信息

    //旋转式样
    switch (m_patternSetPara.rotateStyle)
    {
    case 0:
        break;
    case 1:
        g_pCurEmbData->setRotate90(true);
        break;
    case 2:
        g_pCurEmbData->setMirror(3);
        break;
    case 3:
        g_pCurEmbData->setRotate90(false);
        break;
    case 4:
        g_pCurEmbData->setMirror(1);
        break;
    case 5:
        g_pCurEmbData->setMirror(1);
        g_pCurEmbData->setRotate90(true);
        break;
    case 6:
        g_pCurEmbData->setMirror(2);
        break;
    case 7:
        g_pCurEmbData->setMirror(1);
        g_pCurEmbData->setRotate90(false);
        break;
    }

    //旋转
    g_pCurEmbData->setRotate(360-m_patternSetPara.rotateAngle);

    g_pCurEmbData->getAbsDatRangeXY();//获得单个图元的宽高范围
    g_pCurEmbData->setDatSizeChange(m_patternSetPara.scanX, m_patternSetPara.scanY);   // 设置尺寸变化（缩放）

    //移动起始点改在设置尺寸之后
    //g_pCurEmbData->moveDataBeginPonit(m_patternSetPara.left * 10, m_patternSetPara.front * 10);

    //除qui和quix之外格式进行按固定针步拟合，因为qui和quix拟合在转换为绝对坐标之前已经完成
    if( 0 && ext != "QUI" && ext != "QUIX")
    {
        //reFitLine的拟合算法更好
        //g_pCurEmbData->reFitByStep(m_patternSetPara.normalStep);
        g_pCurEmbData->reFitLine(m_patternSetPara.normalStep);
    }

    g_pCurEmbData->setSplitLen(m_patternSetPara.bisect);
    //加锁针
    g_pCurEmbData->addLockStitchs(m_patternSetPara.reinMode, m_patternSetPara.reinNeedles, m_patternSetPara.reinNum);  // 添加锁针针步

    //    //角度修正 存在一定问题 注释原因：原有的角度修正函数存在一定问题，在多针旋梭机型中编写了新的函数使用
    //    #if(0)
    //    g_pCurEmbData->angleCorrectionBak(m_patternSetPara.angleCorrOffset*10);  // 角度修正，修正固定值
    //    #else
    //    // 角度修正，X正负和Y正负分别修正 存在一定问题
    //    g_pCurEmbData->angleCorrectionXY(m_patternSetPara.angleCorrPosX*10,m_patternSetPara.angleCorrNegX*10,m_patternSetPara.angleCorrPosY*10,m_patternSetPara.angleCorrNegY*10);
    //    #endif

#if(0)//昆仑通态操作屏测试用
    {
        PromptDialog *m_pPromptDlgg;
        m_pPromptDlgg = new PromptDialog();
        //正在加载花样提示窗体
        m_pPromptDlgg->initDialog(PromptDialog::BTN_OK);
        m_pPromptDlgg->setTitleStr(tr("Prompt"));
        m_pPromptDlgg->setContentStr(tr("coco1"));
        m_pPromptDlgg->exec();
        QCoreApplication::processEvents(QEventLoop::AllEvents);
    }
#endif

    if (g_emMacType == MACHINE_FLYFLATCUTTING) //平板飞行切割机        coco
    {
        //g_pCurEmbData->outputCurStepData();          // 打印当前数据
        g_pCurEmbData->setCut2ArrangeDataForKnife(); // 清除异常切刀数据 (35-2 ay/ax相等)
        g_pCurEmbData->setCut2RemoveOverLapLines();  // 修改重叠切割线段为偏移线段 bingo
        g_pCurEmbData->setCut2CornerStep();          // 增加拐点数据
        g_pCurEmbData->setCut2FitSplitStep();        // 分割切刀数据   分割数据步长

        ////g_pCurEmbData->setCut2ArrangeData();         // 整理数据(在两种不同数据中增加拐点,同时剔除两个拐点中只有一个数据的情况)
        g_pCurEmbData->setCut2DelEdgeData();         // 删除上下边界的数据

        g_pCurEmbData->setCut2JudgInterval();        // 判断区间
        g_pCurEmbData->setCut2SortNewData();         // 排序&组成新数据

        //////g_pCurEmbData->setCut2WinComp();   // 窗口补偿值
        //
        //g_pCurEmbData->setCut2ArrangeDataForPen();   // 清除异常画笔数据
        //g_pCurEmbData->setCut2ArrangeDataForNew();   // 清除异常切刀数据2 (9-35-9)
        //
        //g_pCurEmbData->setCut2AddCutterComption22();  // 增加圆刀补偿数据
        ////////g_pCurEmbData->setCut2ArrangeData();         // 整理数据(在两种不同数据中增加拐点,同时剔除两个拐点中只有一个数据的情况)
        //g_pCurEmbData->setCut2AddOffsetData();       // 增加偏移数据   分割数据步长  用到
        //g_pCurEmbData->setCut2AddDistanData();       // 增加距离数据(结束码), 用于存放当前窗口中,每个点距离最左边的距离.
        ////////g_pCurEmbData->setCut2ArrangeDataForNewPenAndKnife();    // 清除异常画笔/切刀 数据
        //g_pCurEmbData->setCut2recalculateAngles();   // 重新计算角度 bingo
        g_pCurEmbData->outputCurStepData();          // 打印当前数据
    }
#if(0)//昆仑通态操作屏测试用
    {
        PromptDialog *m_pPromptDlgg;
        m_pPromptDlgg = new PromptDialog();
        //正在加载花样提示窗体
        m_pPromptDlgg->initDialog(PromptDialog::BTN_OK);
        m_pPromptDlgg->setTitleStr(tr("Prompt"));
        m_pPromptDlgg->setContentStr(tr("coco2"));
        m_pPromptDlgg->exec();
        QCoreApplication::processEvents(QEventLoop::AllEvents);
    }
#endif

    if (g_emMacType == MACHINE_FLATCUTTINGMAC) //平板切割机
    {
        //g_pCurEmbData->setCutcontrastData();            // 增加对比数据
        g_pCurEmbData->setCutCornerStep();                // 增加拐点数据      //圆弧转角判断度数
        g_pCurEmbData->setCutAddCutterComption();         // 增加两端补偿      //落刀补偿
        g_pCurEmbData->setCutEccentricCompensation();     // 偏心刀刀尖补偿    //切刀2圆弧补偿半径
        g_pCurEmbData->setCutRotaryCutterData();          // 增加转刀数据      //切刀2圆弧补偿半径  //圆弧补偿步长
        g_pCurEmbData->setCutDecCornerStep();             // 删除拐点数据
        g_pCurEmbData->setCutFitSplitStep();              // 分割切刀数据
        g_pCurEmbData->setCutFitStepData();               // 拟合切刀数据
    }

    resetAllData(); //显示全部花样区域

    u32 paraId = calcCrc16((u8*)(&m_patternSetPara.rotateStyle),sizeof(m_patternSetPara));
    u32 headFileId = g_pCurEmbData->getDsDatHead()->checkCrc + paraId;
    g_pCurEmbData->setDsDatHeadFileID(headFileId);      //将计算得到的fileid写回到数据区
    showPatternPreview();
}

//每十万针主界面加载图片的进度条走一格
void MainWidget::slotChangeProgressBar(int value)
{
    ui->progressBar->setValue(value);
}

//快捷功能中的快捷按钮被点击
void MainWidget::slotQuickBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_quickBtnList.size(); i++)
    {
        if(button == m_quickBtnList[i])
        {
            int idx = (m_curPages-1)*m_itemPerPage+i;
            int enumFun = m_quickItemList[idx].m_enumFunction;
            runCommonBtnFunction(enumFun);
            break;
        }
    }
}

//辅助功能中的辅助功能按钮被点击
void MainWidget::slotAssistBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_assistBtnList.size(); i++)
    {
        if(button == m_assistBtnList[i])
        {
            int idx = (m_curPages-1)*m_itemPerPage+i;
            int enumFun = m_assistItemList[idx].m_enumFunction;
            runAssistBtnFunction(enumFun,i);
            break;
        }
    }
}

//花样设置中的花样设置按钮被点击
void MainWidget::slotPatternSetBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    //执行快捷按钮动作
    for(int i = 0; i < m_patternSetBtnList.size(); i++)
    {
        if(button == m_patternSetBtnList[i])
        {
            int enumFun = m_patternSetItemList[i].m_enumFunction;
            runPatternSetBtnFunction(enumFun,i);
            break;
        }
    }
}

//参数设置中的参数功能按钮被点击
void MainWidget::slotParaTypeBtnClick()
{
    MyButton *button = (MyButton*) this->sender();

    if(button == NULL)
    {
        return;
    }

    QString bStyle = m_setControlStyle.getBottomStyleSheet(ui->buttonParaSet->parent()->objectName());
    QString tStyle = m_setControlStyle.getTopStyleSheet(ui->buttonParaSet->objectName());

    m_pParameterSetDlg->setTypeLogo(tStyle);
    m_pParameterSetDlg->setMainTitle(tr("Parameter setting"));

    //执行快捷按钮动作
    for(int i = 0; i < m_paraSetBtnList.size(); i++)
    {
        if(button == m_paraSetBtnList[i])
        {
            int paraType = m_paraSetItemList[i].m_paraType;
            QString subStr;
            int64_t sort = -1;

            switch (paraType)
            {
            case PARASET_ACTION://动作参数
            case PARASET_SPEED: //速度参数
            case PARASET_POSITION: // 限位参数
            case PARASET_DETECT: //检测参数
                if(g_emMacType != MACHINE_MULTINEEDLEROTARY)
                {
                    if(g_emDebugMode == nodebugMode && g_emUser != repair){
                        m_pMainWidgetFunction->slotUserLogin(repair);
                        if(g_emUser != repair) return;
                    }
                }

                if(paraType == PARASET_POSITION){
                    subStr = tr("Position parameter");//限位参数
                    sort = MC_SORT_POSITION;
                }else if(paraType == PARASET_ACTION){
                    subStr = tr("Action settings");//动作设定
                    sort = MC_SORT_ACTION;
                }else if(paraType == PARASET_SPEED){
                    subStr = tr("Speed parameters");//速度参数
                    sort = MC_SORT_SPEED;
                }else if(paraType == PARASET_DETECT){
                    subStr = tr("Detection parameters");//检测参数
                    sort = MC_SORT_DETECT;
                }
                break;

            case PARASET_SETTING://工作参数
                subStr = tr("Work parameters");//工作参数
                sort = MC_SORT_SETTING;
                break;

            case PARASET_ALL:
                if(g_emDebugMode == nodebugMode && g_emUser != root){
                    m_pMainWidgetFunction->slotUserLogin(root);
                    if(g_emUser != root) return;
                }
                subStr = tr("All parameters");//全部参数
                sort = -1;
                break;
            default:
                break;
            }

            m_pParameterSetDlg->setSubTitle(tr("Parameter setting > ") + subStr);//参数设置 >
            //机器参数和工作参数
            m_pParameterSetDlg->setItemList(g_emUser,PARA_TYPE_MACH|PARA_TYPE_WORK,sort);
            m_pParameterSetDlg->exec();
            break;
        }
    }
}

//设置超级用户图标
void MainWidget::slotSetButtonRootLogo(int level)
{
    ui->buttonUser->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonUser->objectName()+QString::number(level)));
}

//清空花版断线次数
void MainWidget::slotClearPatternBreakLineNum()
{

}

void MainWidget::slotDebugState()
{
    if(g_emDebugMode == debugMode)
    {
        ui->labelTitle->setText(tr("Debugging mode, prohibit sending machine!"));   //调试模式,禁止发机!
        ui->labelTitle->setStyleSheet(warnTextColour());
    }
    else
    {
        setLabelTitleText(g_emMacType);//根据机型显示主界面标题
        ui->labelTitle->setStyleSheet(titleTextColour());
    }
}

void MainWidget::slotReceScanData(QByteArray data)
{
    QString fileName(data.left(data.size() - 1));// 去除结尾 /r
    qDebug()<< "FileName:"<<fileName;
    ui->labelState->setText(tr("scanner data:") + fileName);//扫码数据:
    QFileInfo info(fileName);
    //判断数据格式
    if(QString("DSR") != info.suffix().toUpper())
    {
        ui->labelState->setText(tr("scanner error:") + info.suffix().toUpper());//扫码错误:
        return;
    }

    //遍历文件夹 找到目标文件
    QStringList list;
    QDir apppath(qApp->applicationDirPath());
    QString filePath = apppath.path() + apppath.separator() + PATTERNPATH;
    QString dirPath = QDir(filePath).absolutePath();//为了将"\"变为"/"
    qDebug()<<dirPath;
    QDirIterator it(dirPath, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDirIterator::Subdirectories);
    while(it.hasNext())
    {
        it.next();
        if(it.fileInfo().fileName() == fileName)
        {
            list.append(it.fileInfo().absoluteFilePath());
        }
    }

    if(list.size() == 0)
    {
        ui->labelState->setText(tr("scanner filename not found:") + fileName);//扫码器文件未找到:
        return;
    }

    foreach(QString pathFile, list)
    {
        qDebug() << "Success Find File:"<< pathFile;
    }

    if(list.size() > 0){
        slotShowPatternPara(list.at(0),-1);//直接显示图片 取第一张
    }

}

void MainWidget::slotDebugInfo()
{
    DebugInfo info;//调试信息
    char mDebugInfoStr[1024+1];

    info = g_pMachine->getDebugInfo();
    memcpy(mDebugInfoStr, info.debugInfoStr, 1024);

    mDebugInfoStr[1024] = 0;

    QString strDebugInfoStr;
    strDebugInfoStr.sprintf("%s", mDebugInfoStr);
    if(strDebugInfoStr.length()>0)
    {
        g_pSettings->writeToCsv(strDebugInfoStr,TYPE_DEBUGINFO);//写入csv
    }
}

void MainWidget::onRefreshPatternTimer()
{
    // 文件执行进度(当前针数) labelNeedleIdx
    m_curDatIdx++;
    reSetDatIdx(m_curDatIdx);
    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);
}

//1秒定时器
void MainWidget::onOneSecondTimer()
{
    // 获取系统当前时间
    QDateTime dateTime = QDateTime::currentDateTime();
    ui->labelTime->setText(dateTime.toString("yyyy/MM/dd HH:mm:ss"));
    refConnectUi(dateTime.time().second());//刷新连接

    if(g_emDebugMode == debugMode)
    {
        if (dateTime.time().second() % 5 == 0)
        {
            setLabelTitleText(g_emMacType);//根据机型显示主界面标题
        }
        else
        {
            ui->labelTitle->setText(tr("Debugging mode, prohibit sending machine!"));   //调试模式,禁止发机!
        }
    }

    if ((m_workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
    {
        if (dateTime.time().second() % 2 == 0)
        {
            ui->labelWorkState->setText(tr(""));//模拟缝纫
        }
        else
        {
            ui->labelWorkState->setText(tr("Simulated working"));//模拟工作
        }
    }
}

//5秒定时器
void MainWidget::onFiveSecondTimer()
{
    if(m_conFlag == 0)//已连接
    {

    }
    else
    {
        g_pMachine->setTcpConnectState(1);//将连接状态置为1
    }
    m_conFlag = -1;
}

void MainWidget::onTenMiniteTimer()
{
    s16 rel = m_pMainWidgetFunction->detectWifiConnect();
    if(rel > 0)//已连接
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Connect"));
    }
    else
    {
        ui->buttonWifi->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonWifi->objectName()+"Unconnect"));
    }
}

//1分钟定时器,记录当前系统时间,用于上电时  计算  关机时间
void MainWidget::onOneMinTimer()
{
    // 获取系统当前时间
    QDateTime dateTime = QDateTime::currentDateTime();
    g_pSettings->writeToIniFile(("DateTime/second"),dateTime.toTime_t());//单位为秒
#if(0)
    //30天自动删除是只删除超过30天的记录
    //文件路径
    QDir apppath(qApp->applicationDirPath());
    QString csvfile;
    csvfile = apppath.path() + apppath.separator() + CSV_FILEID;
    //获取文件的创建时间
    QFileInfo info(csvfile);
    qDebug() << info.size();//获取文件大小
    QDateTime dt = info.created();//获取文件创建时间
    int days = dt.daysTo(dateTime);//获取文件相对于当前时间的天数
    if (days >30)
    {
        QFile::remove(csvfile);//大于30天，删除这个文件
    }
#endif
}

//刷新版本信息
void MainWidget::onRefreshVer()
{
    //版本显示
    QString verStr = m_pMainWidgetFunction->getVersionStr();
    //    verStr.sprintf("XPlatForm-RP-HMI-L1910-V%d.%02d.%02d",
    //                   EMB_VER_CODE_Y,
    //                   EMB_VER_CODE_M,
    //                   EMB_VER_CODE_D);

    QString boardVerStr;
    MCInfo info1 = g_pMachine->getMcInfo();
    QString strBoardVer;
    strBoardVer.sprintf("%s",info1.softwareVerStr);

    QStringList listVer = strBoardVer.split(".");//  因为主控改了程序

    if(listVer.length() >= 3)
    {
        QString str1 = listVer.at(0);
        strBoardVer = str1.right(2);
        strBoardVer += listVer.at(1) + listVer.at(2);
    }

    if(strBoardVer.length() > 0)
    {
        boardVerStr = "-DewMock-V" + strBoardVer;
    }

    ui->labelHMIVersion->setText(verStr);//版本:
}

//主界面
void MainWidget::on_buttonMainMenu_clicked()
{
    hideMenuFrame();
    showPatternPreview();
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

//花样设置
void MainWidget::on_buttonPatternSet_clicked()
{
#if(0)
    //如果为当前显示页面，再点击时需隐藏，显示花样页面
    if(ui->framePatternSet->isVisible())
    {
        showPatternPreview();
    }
#endif
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->framePatternSet->setVisible(true);
    ui->buttonPatternSet->setCheckable(true);
    ui->buttonPatternSet->setChecked(true);
}

//参数设定按钮
void MainWidget::on_buttonParaSet_clicked()
{
    s16 paraSort = g_pSettings->readFromIniFile("HMI/paraSort").toInt();

    if(paraSort == 1)//分类显示参数
    {
        hideMenuFrame();
        ui->frameMenuBack->setVisible(true);
        ui->frameParaSet->setVisible(true);
        ui->buttonParaSet->setCheckable(true);
        ui->buttonParaSet->setChecked(true);
    }
    else if(paraSort == 0)//不分类显示参数
    {
        showPatternPreview();

        QString tStyle = m_setControlStyle.getTopStyleSheet(ui->buttonParaSet->objectName());

        m_pParameterSetDlg->setTypeLogo(tStyle);
        m_pParameterSetDlg->setMainTitle(tr("Parameter setting"));
        m_pParameterSetDlg->setSubTitle(tr("Parameter setting > Parameter setting"));
        //机器参数和工作参数
        m_pParameterSetDlg->setItemList(operate,PARA_TYPE_MACH|PARA_TYPE_WORK);
        m_pParameterSetDlg->exec();
    }
}

//快捷功能按钮
void MainWidget::on_buttonShortcutFunction_clicked()
{
    m_curPages = 1; // 当前页
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->frameShortcutFunction->raise();
    ui->frameShortcutFunction->setVisible(true);
    ui->buttonShortcutFunction->setCheckable(true);
    ui->buttonShortcutFunction->setChecked(true);
    if(m_quickItemList.size() > m_itemPerPage)
    {
        ui->buttonShortCutPgDn->setVisible(true);
        ui->buttonShortCutPgUp->setVisible(true);
        ui->labelShortCutPage->setVisible(true);
        refreshPageUi(INTERFACE_SHORTCUT);
    }
}

//辅助功能按钮
void MainWidget::on_buttonAccessFunction_clicked()
{
    m_curPages = 1; // 当前页
    hideMenuFrame();
    ui->frameMenuBack->setVisible(true);
    ui->frameAccessFunction->setVisible(true);
    ui->buttonAccessFunction->setCheckable(true);
    ui->buttonAccessFunction->setChecked(true);
    if(m_assistItemList.size() > m_itemPerPage)
    {
        ui->buttonShortCutPgDn->setVisible(true);
        ui->buttonShortCutPgUp->setVisible(true);
        ui->labelShortCutPage->setVisible(true);
        refreshPageUi(INTERFACE_SHORTCUT);
    }
}

//速度加
void MainWidget::on_buttonSpeedAdd_clicked()
{
    if(g_pMachine != NULL)
    {
        int speed = 0;
        if(m_speedLevel == 1)
        {
            speed = 10;
        }
        else if(m_speedLevel == 2)
        {
            speed = 50;
        }
        else if(m_speedLevel == 3)
        {
            speed = 100;
        }

        g_pMachine->msRpmChange(speed,0);
    }
}

//速度减
void MainWidget::on_buttonSpeedDec_clicked()
{
    if(g_pMachine != NULL)
    {
        int speed = 0;
        if(m_speedLevel == 1)
        {
            speed = -10;
        }
        else if(m_speedLevel == 2)
        {
            speed = -50;
        }
        else if(m_speedLevel == 3)
        {
            speed = -100;
        }

        g_pMachine->msRpmChange(speed,0);
    }
}

void MainWidget::on_buttonNineBtnUp_pressed()
{
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC){
            g_pMachine->manualAction(XY_MOVE_FRONT_CUTTING, m_speedLevel);
        }
        else if(g_emMacType == MACHINE_FLYFLATCUTTING)
        {
            g_pMachine->manualAction(XY_MOVE_BACK_CUTTING, m_speedLevel);
        }
        else
        {
            g_pMachine->manualAction(XY_MOVE_FRONT, m_speedLevel);
        }
    }
}

void MainWidget::on_buttonNineBtnUp_released()
{
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC){
            g_pMachine->motoMove(XY_MOVE_FRONT_CUTTING, MT_MOVE_DIR_STOP, 0);
        }
        else if(g_emMacType == MACHINE_FLYFLATCUTTING)
        {
            g_pMachine->motoMove(XY_MOVE_BACK_CUTTING, MT_MOVE_DIR_STOP, 0);
        }
        else
        {
            g_pMachine->motoMove(XY_MOVE_FRONT, MT_MOVE_DIR_STOP, 0);
        }
    }
}

void MainWidget::on_buttonNineBtnDown_pressed()
{
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC){
            g_pMachine->manualAction(XY_MOVE_BACK_CUTTING, m_speedLevel);
        }
        else if(g_emMacType == MACHINE_FLYFLATCUTTING)
        {
            g_pMachine->manualAction(XY_MOVE_FRONT_CUTTING, m_speedLevel);
        }
        else
        {
            g_pMachine->manualAction(XY_MOVE_BACK, m_speedLevel);
        }
    }
}

void MainWidget::on_buttonNineBtnDown_released()
{
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC){
            g_pMachine->motoMove(XY_MOVE_BACK_CUTTING, MT_MOVE_DIR_STOP, 0);
        }
        else if(g_emMacType == MACHINE_FLYFLATCUTTING)
        {
            g_pMachine->motoMove(XY_MOVE_FRONT_CUTTING, MT_MOVE_DIR_STOP, 0);
        }
        else
        {
            g_pMachine->motoMove(XY_MOVE_BACK, MT_MOVE_DIR_STOP, 0);
        }
    }
}

void MainWidget::on_buttonNineBtnLeft_pressed()
{
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC || g_emMacType == MACHINE_FLYFLATCUTTING){
            g_pMachine->manualAction(XY_MOVE_LEFT_CUTTING, m_speedLevel);
        }else{
            g_pMachine->manualAction(XY_MOVE_LEFT, m_speedLevel);
        }
    }
}

void MainWidget::on_buttonNineBtnLeft_released()
{
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC || g_emMacType == MACHINE_FLYFLATCUTTING){
            g_pMachine->motoMove(XY_MOVE_LEFT_CUTTING, MT_MOVE_DIR_STOP, 0);
        }else{
            g_pMachine->motoMove(XY_MOVE_LEFT, MT_MOVE_DIR_STOP, 0);
        }
    }
}

void MainWidget::on_buttonNineBtnRight_pressed()
{
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC || g_emMacType == MACHINE_FLYFLATCUTTING){
            g_pMachine->manualAction(XY_MOVE_RIGHT_CUTTING, m_speedLevel);
        }else{
            g_pMachine->manualAction(XY_MOVE_RIGHT, m_speedLevel);
        }
    }
}

void MainWidget::on_buttonNineBtnRight_released()
{
    setFrameNineBtnStyle();
    if(g_pMachine != NULL)
    {
        if(g_emMacType == MACHINE_FLATCUTTINGMAC || g_emMacType == MACHINE_FLYFLATCUTTING){
            g_pMachine->motoMove(XY_MOVE_RIGHT_CUTTING, MT_MOVE_DIR_STOP, 0);
        }else{
            g_pMachine->motoMove(XY_MOVE_RIGHT, MT_MOVE_DIR_STOP, 0);
        }
    }
}

void MainWidget::on_buttonNineBtnMiddle_pressed()
{
    m_speedLevel = m_speedLevel + 1;
    if(m_speedLevel > 3)
    {
        m_speedLevel = 1;
    }

    bool cVal = ui->buttonPatternSet->isEnabled();//按钮是否失能,是否锁界面

    if(cVal == true)
    {
        //        ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet("frameNineBtnMiddle"));
    }
}

void MainWidget::on_buttonNineBtnMiddle_released()
{
    bool cVal = ui->buttonPatternSet->isEnabled();//按钮是否失能,是否锁界面

    if(cVal == true)
    {
        //        ui->frameNineBtn->setStyleSheet(m_setControlStyle.getBorderImageStyleSheet(ui->frameNineBtn->objectName()));
    }

    setFrameNineBtnStyle();
}

//前进回退
//void MainWidget::on_buttonNineBtn1_clicked()
//{
//    funForwardOrBack();
//}

void MainWidget::on_buttonNineBtn1_clicked()
{
    runCommonBtnFunction(m_nineBtn.value(1).m_enumFunction);
}

void MainWidget::on_buttonNineBtn2_clicked()
{
    runCommonBtnFunction(m_nineBtn.value(2).m_enumFunction);
}

void MainWidget::on_buttonNineBtn3_clicked()
{
    runCommonBtnFunction(m_nineBtn.value(3).m_enumFunction);
}

void MainWidget::on_buttonNineBtn4_clicked()
{
    runCommonBtnFunction(m_nineBtn.value(4).m_enumFunction);
}

void MainWidget::on_buttonNeedleBegin_clicked()
{
    m_forwardBackNeedleIdx = 0;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleEnd_clicked()
{
    m_forwardBackNeedleIdx = g_pCurEmbData->getStitchNums();  //总针数
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec1_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 1;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd1_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 1;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec10_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 10;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd10_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 10;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec100_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 100;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd100_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 100;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec1000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 1000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd1000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 1000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleDec10000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx - 10000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonNeedleAdd10000_clicked()
{
    m_forwardBackNeedleIdx = m_forwardBackNeedleIdx + 10000;
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);
}

void MainWidget::on_buttonElementAdd_clicked()
{
    m_forwardBackNeedleIdx = g_pCurEmbData->getNextElementIndex(m_forwardBackNeedleIdx);//获得下一个图元的第一缝纫针步
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);// 更新针数
}

void MainWidget::on_buttonElementDec_clicked()
{
    int index = m_forwardBackNeedleIdx -1;
    m_forwardBackNeedleIdx = g_pCurEmbData->getPreOrThisElementIndex(index < 0 ? 0 : index);//上一个图元或当前图元的第一缝纫针步
    addOrDecNeedleIdx(m_forwardBackNeedleIdx);// 更新针数
}

void MainWidget::on_buttonForwardBackOk_clicked()
{
    if ((m_mcStatus.workStatus & WORK_STA_BUSY) != 0)    // 下位机在执行动作
    {
        return;
    }

    //g_pMachine->setFileExecProgress(0, m_curFileID, m_expara);
    g_pMachine->fastJump(m_expara.newIdx);//前进回退
    ui->frameForwardBack->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

void MainWidget::on_buttonForwardBackCancel_clicked()
{
    g_pCurEmbData->setExecIndex(m_curDatIdx);// 更新针数

    QPixmap patternPix = g_pCurEmbData->getPreviewImage();
    ui->labelPatternView->setPixmap(patternPix);

    ui->frameForwardBack->setVisible(false);
    setUiBtnEnable(true);
    ui->buttonMainMenu->setCheckable(true);
    ui->buttonMainMenu->setChecked(true);
}

//退出登录
void MainWidget::on_buttonUser_clicked()
{
    //退回到无密码的普通用户
    if(g_emUser == repair || g_emUser == root)
    {
        m_pMainWidgetFunction->funExitRoot();
        ui->buttonUser->setStyleSheet(m_setControlStyle.getStyleSheet(ui->buttonUser->objectName()));
    }
}

void MainWidget::mousePressEvent(QMouseEvent *e)
{
    if ( e->button() == Qt::LeftButton)
    {
        mousePressX = e->x();
        mousePressY = e->y();
        mouseReleaseX = 0;
        mouseReleaseY = 0;
    }
}

void MainWidget::mouseReleaseEvent(QMouseEvent *e)
{
    if ( e->button() == Qt::LeftButton)
    {
        mouseReleaseX = e->x();
        mouseReleaseY = e->y();
    }

    int width = this->width();
    int height = this->height();
    if ((mousePressX >= 0 && mousePressX <= 100)  &&
            ((mousePressY >= (height - 100)) && mousePressY <= height) &&
            ((mouseReleaseX >= (width - 100)) && ((mouseReleaseX <= (width)))) &&
            ((mouseReleaseY >= (height - 100)) && mouseReleaseY <= height)
            )
    {
        m_usbPath.clear();//清空路径字符串 //优盘路径
        m_usbPath = m_pMainWidgetFunction->detectUsb();//优盘检测
        if(m_usbPath.length() <= 0)
        {
            //优盘不存在
            return;
        }
        else
        {
            QPixmap pixmap=QPixmap::grabWindow(this->winId(),0,0,this->width(),this->height());//截屏存放在pixmap
            QString name_pc = m_usbPath +  "EMB" + //
                    QDateTime::currentDateTime().toString("yyyyMMdd") +//获取时期时间
                    +"_"+
                    QDateTime::currentDateTime().toString("hhmmss")    + ".png";

            pixmap.save(name_pc,"png"); // 路径

            if (m_usbPath!= "")
            {
                //截屏效果
                ui->labelScreenshot->show();
                SetStyle setControlStyle;
                setControlStyle.setUiName(this->objectName());
                ui->labelScreenshot->setStyleSheet(setControlStyle.getStyleSheet("labelScreenshot"));
                QTimer::singleShot(2000,ui->labelScreenshot,SLOT(hide())); // 停留一秒  隐藏
            }
        }
    }

    mousePressX = 0;
    mousePressY = 0;
    mouseReleaseX = 0;
    mouseReleaseY = 0;
}

void MainWidget::on_buttonStartStop_clicked()
{
    g_pMachine->pauseWork();
}

void MainWidget::on_buttonMove_pressed()
{

#ifdef Q_OS_LINUX
#else
    //qDebug()<<"buttonMove_pressed";
    QPoint msPos;
    int msX,msY;
    int uiX,uiY;

    uiX = g_mainWidgetPos.x();
    uiY = g_mainWidgetPos.y();
    msPos = QCursor::pos();
    msX = msPos.x();
    msY = msPos.y();
    ui->buttonMove->setChecked(true);

    do
    {
        msPos = QCursor::pos();
        g_mainWidgetPos.setX((msPos.x() - msX) + uiX);
        g_mainWidgetPos.setY((msPos.y() - msY) + uiY);

        this->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
        if(ui->buttonMove->isChecked() == false)
        {
            break;
        }
        QCoreApplication::processEvents(QEventLoop::AllEvents);

    }while(1);


    m_pPatternSelectWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
    m_pParameterSetDlg->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
    m_pPatternManageWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
    m_pSensorInputWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
    m_pControlActionWi->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());

    m_pMainWidgetFunction->moveDlgPos();
#endif
}

void MainWidget::on_buttonMove_released()
{
#ifdef Q_OS_LINUX
#else
    ui->buttonMove->setChecked(false);
    //qDebug()<<"on_buttonMove_released";
#endif
}

void MainWidget::on_buttonAssistPgDn_clicked()
{
    m_curPages++;
    refreshPageUi(INTERFACE_ACCESS);
}

void MainWidget::on_buttonAssistPgUp_clicked()
{
    m_curPages--;
    refreshPageUi(INTERFACE_ACCESS);
}

void MainWidget::on_buttonShortCutPgDn_clicked()
{
    m_curPages++;
    refreshPageUi(INTERFACE_SHORTCUT);
}

void MainWidget::on_buttonShortCutPgUp_clicked()
{
    m_curPages--;
    refreshPageUi(INTERFACE_SHORTCUT);
}

//btn3、4 为了多针旋梭机器添加
void MainWidget::on_buttonNineBtn3_released()
{
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        if((g_pMachine != NULL))
        {
            g_pMachine->outputCtrl(0x0098, DOWN_CLOSE_OFF, 0);
        }
    }
}

void MainWidget::on_buttonNineBtn3_pressed()
{
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        if((g_pMachine != NULL))
        {
            g_pMachine->outputCtrl(0x0098, UP_OPEN_ON, 0);
        }
    }
}

void MainWidget::on_buttonNineBtn4_released()
{
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        if((g_pMachine != NULL))
        {
            g_pMachine->outputCtrl(0x0099, DOWN_CLOSE_OFF, 0);
        }
    }
}
void MainWidget::on_buttonNineBtn4_pressed()
{
    if(g_emMacType == MACHINE_MULTINEEDLEROTARY)
    {
        if((g_pMachine != NULL))
        {
            g_pMachine->outputCtrl(0x0099, UP_OPEN_ON, 0);
        }
    }
}
